├── Template.ooutline ├── README.md └── OmniOutliner MD Export.applescript /Template.ooutline: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bcdavasconcelos/Ooutline-to-PDF/main/Template.ooutline -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Ooutline to PDF 2 | 3 | This template is for converting a text directly from OmniOutliner to PDF using Pandoc preserving internal row-level cross-references. `OO/Rtf → Markdown → LaTeX → PDF` 4 | 5 | Use the styles in the template to create headings, block-quotes, lists and so on. Italics, bold and links will be converted automatically. Use row link to reference another row. 6 | -------------------------------------------------------------------------------- /OmniOutliner MD Export.applescript: -------------------------------------------------------------------------------- 1 | use AppleScript version "2.4" -- Yosemite (10.10) or later 2 | use scripting additions 3 | -- use script "RegexAndStuffLib" 4 | 5 | -- bcdav 2021-07-11-12-47 6 | -- https://github.com/bcdavasconcelos/Ooutline-to-PDF 7 | -- with a little help from my friends (https://discourse.omnigroup.com/t/script-to-convert-oo-to-markdown-tex-and-pdf-using-pandoc/31429/15) 8 | 9 | property UseSelection : false -- if false → all rows 10 | property IncludeRowNote : true 11 | property ConvertWithPandoc : false 12 | property OpenAfterConversion : true 13 | 14 | set PandocPath to "export PATH=/Library/TeX/texbin:$PATH && /usr/local/bin/pandoc" 15 | set PandocDefaults to "-drefs2 -dabntex -dpdf" 16 | 17 | 18 | set theCompleteText to {} 19 | 20 | set theRows to {} 21 | 22 | tell application "OmniOutliner" 23 | 24 | set theFile to get file of front document 25 | set thePath to POSIX path of theFile 26 | 27 | tell front document 28 | 29 | 30 | if UseSelection then 31 | set theRows to selected rows 32 | else 33 | set theRows to rows 34 | end if 35 | 36 | -- set theRow to item 1 of theRows 37 | repeat with theRow in theRows 38 | 39 | 40 | set {RowId, RowText, RowNote, RowStyles, RowPrefix, RowSufix} to {"", "", "", "", "", ""} -- clean variables 41 | 42 | -- 1. Row styles 43 | 44 | set RowId to the id of theRow 45 | set RowId to "[]{#" & RowId & "}" 46 | set RowStyles to name of named styles of style of theRow -- retrieve named Styles 47 | 48 | 49 | set {RowPrefix, RowSufix} to my TranslateStylesToMarkdown(RowStyles, RowId) -- retrieve what should come before or/and after the row text 50 | 51 | 52 | -- 2. Main text with bold, italics and links 53 | 54 | set {lsText, lsFont, lsLinks, lsStyles} to {its text, its font, its attribute "link" of style, its name of named styles of styles} of topic's attribute runs of theRow -- necessary data for translating to md 55 | 56 | set RowText to my TranslateRtfToMarkdown(lsText, lsFont, lsLinks, lsStyles) -- translate rtf to md 57 | 58 | -- 3. Note text with bold, italics and links 59 | 60 | set {lsTextofNote, lsFontofNote, lsLinksofNote, lsStylesofNote} to {its text, its font, its attribute "link" of style, its name of named styles of styles} of note's attribute runs of theRow -- necessary data for translating to md 61 | set RowNote to my TranslateRtfToMarkdown(lsTextofNote, lsFontofNote, lsLinksofNote, lsStylesofNote) -- translate rtf to md 62 | 63 | 64 | set RowText to RowPrefix & RowText & RowSufix & linefeed 65 | 66 | if IncludeRowNote then 67 | if RowNote is not "" then set RowText to RowText & linefeed & RowNote & " " & linefeed & linefeed 68 | end if 69 | 70 | set theCompleteText to theCompleteText & RowText 71 | 72 | 73 | end repeat 74 | 75 | set theCompleteText to my RegexReplace(theCompleteText) 76 | 77 | set the clipboard to (theCompleteText as text) 78 | -- return theCompleteText as text 79 | 80 | end tell 81 | end tell 82 | 83 | 84 | if ConvertWithPandoc then 85 | set theMDPath to thePath & ".md" 86 | set thePDFPath to thePath & ".pdf" 87 | 88 | do shell script "touch " & quoted form of theMDPath & " && LANG=pt_BR.UTF-8 pbpaste > " & quoted form of theMDPath 89 | set theSH to PandocPath & space & "-s" & space & quoted form of theMDPath & space & PandocDefaults & space & "-o" & space & quoted form of thePDFPath 90 | if OpenAfterConversion then set theSH to theSH & "&& open " & quoted form of thePDFPath 91 | do shell script theSH 92 | 93 | end if 94 | 95 | 96 | on fixHomePath(thePath) 97 | if thePath contains "~/" then 98 | set thePath to replacetext(thePath, "~/", "$HOME/") 99 | else 100 | set HomePath to (POSIX path of (path to home folder)) 101 | set thePath to replacetext(thePath, HomePath, "$HOME/") 102 | end if 103 | return thePath 104 | end fixHomePath 105 | 106 | 107 | on replacetext(theString, old, new) 108 | set {TID, text item delimiters} to {text item delimiters, old} 109 | set theStringItems to text items of theString 110 | set text item delimiters to new 111 | set theString to theStringItems as text 112 | set text item delimiters to TID 113 | return theString 114 | end replacetext 115 | 116 | 117 | on RegexReplace(theText) 118 | 119 | -- set theText to regex change theText search pattern "(-@.+?\\b)" replace template "[$1]" 120 | -- set theText to regex change theText search pattern "(\\p{Greek}+)" replace template "\\\\grc{$1}" 121 | 122 | return theText 123 | end RegexReplace 124 | 125 | on TranslateStylesToMarkdown(RowStyles, RowId) 126 | set {pre, pos} to {RowId, " " & linefeed} 127 | 128 | if RowStyles contains "Heading 1" then 129 | set {pre, pos} to {RowId & " " & linefeed & linefeed & "# ", " " & linefeed} 130 | else if RowStyles contains "Heading 2" then 131 | set {pre, pos} to {RowId & " " & linefeed & linefeed & "## ", " " & linefeed} 132 | else if RowStyles contains "Heading 3" then 133 | set {pre, pos} to {RowId & " " & linefeed & linefeed & "### ", " " & linefeed} 134 | else if RowStyles contains "Heading 4" then 135 | set {pre, pos} to {RowId & " " & linefeed & linefeed & "#### ", " " & linefeed} 136 | else if RowStyles contains "Heading 5" then 137 | set {pre, pos} to {RowId & " " & linefeed & linefeed & "##### ", " " & linefeed} 138 | else if RowStyles contains "Heading 6" then 139 | set {pre, pos} to {RowId & " " & linefeed & linefeed & "###### ", " " & linefeed} 140 | else if RowStyles contains "Heading 7" then 141 | set {pre, pos} to {RowId & " " & linefeed & linefeed & "####### ", " " & linefeed} 142 | else if RowStyles contains "HeadingNo" then 143 | set {pre, pos} to {RowId & " " & linefeed & linefeed & "# ", " {-} " & linefeed} 144 | else if RowStyles contains "YAML" then 145 | set {pre, pos} to {"", ""} 146 | else if RowStyles contains "Ordered List" then 147 | set {pre, pos} to {"1. ", ""} 148 | else if RowStyles contains "Unordered List" then 149 | set {pre, pos} to {"- ", ""} 150 | else if RowStyles contains "Paragraph" then 151 | set {pre, pos} to {linefeed & RowId & " " & linefeed, " " & linefeed} 152 | else if RowStyles contains "YAMLitem" then 153 | set {pre, pos} to {"", ": |"} 154 | else if RowStyles contains "YAMLtext" then 155 | set {pre, pos} to {linefeed & " ", " "} 156 | else if RowStyles contains "Small" then 157 | set {pre, pos} to {linefeed & "", ""} 158 | else if RowStyles contains "Blockquote" then 159 | set {pre, pos} to {linefeed & "> ", " " & RowId & " " & linefeed} 160 | else if RowStyles contains "Code" then 161 | set {pre, pos} to {linefeed & RowId & " " & linefeed & "> ", " " & linefeed} 162 | else if RowStyles contains "Comment" then 163 | set {pre, pos} to {linefeed & "" & linefeed} 164 | else if RowStyles contains "Ignore" then 165 | set {pre, pos} to {linefeed & "" & linefeed} 166 | end if 167 | 168 | return {pre, pos} 169 | end TranslateStylesToMarkdown 170 | 171 | on TranslateRtfToMarkdown(lsText, lsFont, lsLinks, lsStyles) 172 | using terms from application "OmniOutliner" 173 | set outTxt to "" 174 | 175 | repeat with i from 1 to lsText's length 176 | 177 | set {thePrefix, theSufix} to {"", ""} 178 | set {aStr, aFont, aLink, aStyle} to {lsText's item i, lsFont's item i, lsLinks's item i, lsStyles's item i} 179 | 180 | if aFont contains "bold" or aFont contains "black" or aFont contains "Bd" then set {thePrefix, theSufix} to {"**", "**"} 181 | 182 | if aFont contains "italic" or aFont contains "It" then set {thePrefix, theSufix} to {thePrefix & "*", theSufix & "*"} 183 | 184 | 185 | if has local value of aLink then 186 | set theLink to value of aLink 187 | if theLink contains "omnioutliner" then 188 | set theLink to my replacetext(theLink, "omnioutliner:///open?row=", "#") 189 | set {thePrefix, theSufix} to {thePrefix & "[", "](" & theLink & ")" & theSufix} 190 | else 191 | set {thePrefix, theSufix} to {thePrefix & "[", "](" & theLink & ")" & theSufix} 192 | end if 193 | end if 194 | 195 | if aStyle contains "Index" then 196 | set {thePrefix, theSufix} to {"\\index{", "}"} 197 | end if 198 | 199 | set outTxt to outTxt & thePrefix & aStr & theSufix 200 | 201 | end repeat 202 | return outTxt 203 | end using terms from 204 | end TranslateRtfToMarkdown 205 | 206 | --------------------------------------------------------------------------------