Commit d11e92f195

d11e92f195e9831e823bc63b4bcc8b25f47187ed

parent: d30c86872a

Verified · cmc

cmc <hello@cleberg.net> · 2026-11-21 19:45 UTC

Refuse LaTeX export of a link description holding ]]

Layout: unified · split

Sources/OrgCore/Export/LaTeXExport.swift +4
@@ -1580,6 +1580,10 @@ final class LaTeXRenderer {
1580 if node.firstChild(.linkDescription)?.descendants().contains(where: { $0.kind == .link }) == true { 1580 if node.firstChild(.linkDescription)?.descendants().contains(where: { $0.kind == .link }) == true {
1581 throw Unsupported(reason: "Links in link descriptions") 1581 throw Unsupported(reason: "Links in link descriptions")
1582 } 1582 }
1583 // Org's description ends at the first `]]`, where the parser's ends at the balancing `]`.
1584 if let d = node.firstChild(.linkDescription)?.text, (d.dropFirst() + "]").contains("]]") {
1585 throw Unsupported(reason: "]] in link descriptions")
1586 }
1583 if let d = node.firstChild(.linkDescription)?.text, d.firstMatch(of: /^(?:[A-Za-z]+:\S+|<[^>]+>)$/) != nil { 1587 if let d = node.firstChild(.linkDescription)?.text, d.firstMatch(of: /^(?:[A-Za-z]+:\S+|<[^>]+>)$/) != nil {
1584 throw Unsupported(reason: "Images as link descriptions") 1588 throw Unsupported(reason: "Images as link descriptions")
1585 } 1589 }
Tests/OrgCoreTests/LaTeXExportTests.swift +4
@@ -109,6 +109,7 @@ struct LaTeXExportTests {
109 "Run [[elisp:(+ 1 2)][add]] and [[elisp:(message \"50% #x\")]], [[shell:ls ~/x_y][list]] [[shell:echo $HOME]], [[help:car][car]] [[shortdoc:string]].\n", 109 "Run [[elisp:(+ 1 2)][add]] and [[elisp:(message \"50% #x\")]], [[shell:ls ~/x_y][list]] [[shell:echo $HOME]], [[help:car][car]] [[shortdoc:string]].\n",
110 "Plain shell:ls and elisp:foo and help:car here.\nGet ftp://x.org/f now, news:comp.x and mailto:a@b.c, shortdoc:string HTTPS://a.b/c.\nshell:echo_$x% and shell:ls\tx shell:ls[x elisp:(foo) FILE:a.txt File:b.org::s FILE:/abs FILE://h/p.\n[[https://a.b][see shell:ls]] *shell:ls* and\n| news:x |\n", 110 "Plain shell:ls and elisp:foo and help:car here.\nGet ftp://x.org/f now, news:comp.x and mailto:a@b.c, shortdoc:string HTTPS://a.b/c.\nshell:echo_$x% and shell:ls\tx shell:ls[x elisp:(foo) FILE:a.txt File:b.org::s FILE:/abs FILE://h/p.\n[[https://a.b][see shell:ls]] *shell:ls* and\n| news:x |\n",
111 "* Heading shell:ls\nx\n", 111 "* Heading shell:ls\nx\n",
112 "[[https://a.b][[x] y]] and [[https://a.b][x [y] z]] after.\n",
112 "Run [[elisp:(+ 1\n 2)]] and see [[https://a.b/c\n d]] ok, [[shell:a \n\tb][two\n lines]] and [[elisp:a\tb\n c]].\n", 113 "Run [[elisp:(+ 1\n 2)]] and see [[https://a.b/c\n d]] ok, [[shell:a \n\tb][two\n lines]] and [[elisp:a\tb\n c]].\n",
113 "* Target section\nA <<anchor>> here and [[anchor]] and [[anchor][desc]].\n* Other\nSee [[*Target section]] and [[Target section][named]] and [[#cid]].\n* Third\n:PROPERTIES:\n:CUSTOM_ID: cid\n:END:\nx\n", 114 "* Target section\nA <<anchor>> here and [[anchor]] and [[anchor][desc]].\n* Other\nSee [[*Target section]] and [[Target section][named]] and [[#cid]].\n* Third\n:PROPERTIES:\n:CUSTOM_ID: cid\n:END:\nx\n",
114 "#+OPTIONS: num:nil\n* Head\nSee [[*Head]].\n", 115 "#+OPTIONS: num:nil\n* Head\nSee [[*Head]].\n",
@@ -354,6 +355,9 @@ struct LaTeXExportTests {
354 let pre = "* Top\n:PROPERTIES:\n:EXPORT_LATEX_CLASS_PRE: \\x\n:END:\nBody.\n" 355 let pre = "* Top\n:PROPERTIES:\n:EXPORT_LATEX_CLASS_PRE: \\x\n:END:\nBody.\n"
355 #expect(ExportScope.subtree(pre, at: 0).flatMap(reason) == "#+LATEX_CLASS_PRE") 356 #expect(ExportScope.subtree(pre, at: 0).flatMap(reason) == "#+LATEX_CLASS_PRE")
356 #expect(reason("#+OPTIONS: tags:not-in-toc\n* 100% done :a:\n")?.hasPrefix("% in a heading") == true) 357 #expect(reason("#+OPTIONS: tags:not-in-toc\n* 100% done :a:\n")?.hasPrefix("% in a heading") == true)
358 for org in ["[[elisp:foo][[[file:a.png]]]]\n", "[[https://a.b][[[x]] y]]\n", "[[https://a.b][[x]]]\n", "[[a][b [fn:1]]]\n\n[fn:1] d\n"] {
359 #expect(reason(org) == "]] in link descriptions")
360 }
357 #expect(reason("See id:abc.\n") == "Plain links of type id") 361 #expect(reason("See id:abc.\n") == "Plain links of type id")
358 #expect(reason("See info:emacs here.\n") == "Plain links of type info") 362 #expect(reason("See info:emacs here.\n") == "Plain links of type info")
359 #expect(reason("See FILE:a.png here.\n") == "Plain image links") 363 #expect(reason("See FILE:a.png here.\n") == "Plain image links")
docs/manual/guide/12-export.org +1 −1
@@ -236,7 +236,7 @@ It reads:
236 236
237=#+TITLE=, =#+SUBTITLE=, =#+AUTHOR=, =#+DATE=, =#+KEYWORDS=, =#+DESCRIPTION=, =#+LANGUAGE= and =#+OPTIONS= work as in Emacs, as do the tags and =COMMENT= that leave headings out (see /Which headings are exported/). Body-only and subtree export are in the export dialog. In a subtree export, the heading's =EXPORT_LATEX_CLASS=, =EXPORT_LATEX_CLASS_OPTIONS=, =EXPORT_LATEX_HEADER=, =EXPORT_LATEX_HEADER_EXTRA=, =EXPORT_LATEX_COMPILER=, =EXPORT_SUBTITLE=, =EXPORT_KEYWORDS=, =EXPORT_DESCRIPTION= and =EXPORT_LANGUAGE= properties replace the file's keywords. As in Emacs, a =PROPERTY+= line adds its value to the property's, after a space. 237=#+TITLE=, =#+SUBTITLE=, =#+AUTHOR=, =#+DATE=, =#+KEYWORDS=, =#+DESCRIPTION=, =#+LANGUAGE= and =#+OPTIONS= work as in Emacs, as do the tags and =COMMENT= that leave headings out (see /Which headings are exported/). Body-only and subtree export are in the export dialog. In a subtree export, the heading's =EXPORT_LATEX_CLASS=, =EXPORT_LATEX_CLASS_OPTIONS=, =EXPORT_LATEX_HEADER=, =EXPORT_LATEX_HEADER_EXTRA=, =EXPORT_LATEX_COMPILER=, =EXPORT_SUBTITLE=, =EXPORT_KEYWORDS=, =EXPORT_DESCRIPTION= and =EXPORT_LANGUAGE= properties replace the file's keywords. As in Emacs, a =PROPERTY+= line adds its value to the property's, after a space.
238 238
239A file with something this export doesn't handle stops with "Can't export to LaTeX: " and what it was, rather than giving a =.tex= that differs from Emacs's: a LaTeX class other than the three, Babel or Polyglossia in the header, citations, radio targets, inline tasks, table.el tables, inline source blocks and calls, =#+CALL=, source blocks exported with their results, footnote definitions of several paragraphs, footnotes in headings, tables or item tags, =:mode math= and long tables, =UNNUMBERED= and =ALT_TITLE=, =tex:verbatim=, a quote or center block whose first line holds only spaces and whose second line is not blank, a keyword such as =#+SUBTITLE= repeated with an empty value, and =#+OPTIONS= items other than =toc=, =num=, =H=, =tags=, =todo=, =pri=, =^=, =tex=, =title=, =author=, =date=, =-= and =timestamp= set to something other than Org's default. A link Emacs can't resolve stops the export in both, including a link to a heading, target or named element the export leaves out. On iOS the share sheet stops and the message shows at the bottom of the screen. Publishing to LaTeX stops with the file's name in the message. In the download version, when Emacs is installed, such a file is exported by Emacs instead (see /Exporting through Emacs/). 239A file with something this export doesn't handle stops with "Can't export to LaTeX: " and what it was, rather than giving a =.tex= that differs from Emacs's: a LaTeX class other than the three, Babel or Polyglossia in the header, citations, radio targets, inline tasks, table.el tables, inline source blocks and calls, =#+CALL=, source blocks exported with their results, footnote definitions of several paragraphs, footnotes in headings, tables or item tags, =:mode math= and long tables, =UNNUMBERED= and =ALT_TITLE=, =tex:verbatim=, a quote or center block whose first line holds only spaces and whose second line is not blank, a keyword such as =#+SUBTITLE= repeated with an empty value, plain (unbracketed) links of types it doesn't write, such as =id:= and =info:=, plain links to images, a link description holding =]]=, and =#+OPTIONS= items other than =toc=, =num=, =H=, =tags=, =todo=, =pri=, =^=, =tex=, =title=, =author=, =date=, =-= and =timestamp= set to something other than Org's default. A link Emacs can't resolve stops the export in both, including a link to a heading, target or named element the export leaves out. On iOS the share sheet stops and the message shows at the bottom of the screen. Publishing to LaTeX stops with the file's name in the message. In the download version, when Emacs is installed, such a file is exported by Emacs instead (see /Exporting through Emacs/).
240 240
241* Word, RTF and plain text 241* Word, RTF and plain text
242 242