Skip to content

Commit

Permalink
tweak pandoc-run.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
iandol committed Mar 6, 2024
1 parent cbceab8 commit a86c883
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions pandoc-run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# encoding: utf-8

# This script rewrites markdown compiled from Scrivener and runs Pandoc.
# Version: 0.1.01
# Version: 0.1.02

Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8
Expand Down Expand Up @@ -51,6 +51,7 @@ def isRecent(infile) # checks if a file is less than 3 minutes old
if fileType.nil? || fileType !~ /(plain|markdown|typst|html|pdf|epub|docx|latex|odt|beamer|revealjs|pptx)/
fileType = 'docx'
end
puts "--> Output Filetype: #{fileType}"

makePath()
editedFile = infilename.gsub(/\.[q]?md$/,"-edit.md") # output to [name]-edit.md
Expand All @@ -63,12 +64,6 @@ def isRecent(infile) # checks if a file is less than 3 minutes old
tout = ""
text = file.read

# replace any ${USERHOME} with the user's home directory
text.gsub!(/\${USERHOME}\//, ENV['HOME']+'/')

# cosmetic only: remove long runs (4 or more) of newlines
text.gsub!(/\n{4,}/,"\n\n")

# finds footnotes and removes escaping of _
fnID = /^\[\^.+?\]:.+/
text.each_line { |line|
Expand All @@ -92,20 +87,19 @@ def isRecent(infile) # checks if a file is less than 3 minutes old
puts "--> Parsing took: " + tend.to_s + "s"

output = infilename.gsub(/\.[q]?md$/,".#{fileType}")
cmd = 'pandoc --verbose -s --citeproc --lua-filter=' + filter +
' --bibliography=' + bib + ' --output=' + output + ' ' + editedFile
cmd = 'pandoc -s --verbose --citeproc --lua-filter=' + filter +
' --bibliography=' + bib + ' --to=' + fileType + ' --output=' + output + ' ' + editedFile

# Build and run our pandoc command
puts "\n--> Running Command: #{cmd}"
puts %x(#{cmd})

# now try to open the resultant file
fileType = 'html' if fileType.match(/revealjs|s5|slidous|html5/)
if File.file?(output) && isRecent(output)
`open #{output}`
else
puts "There was some problem opening #{output}, check compiler log…"
end

# open any log file (generated from scrivener's post-processing)
`open Pandoc.log` if File.file?('Pandoc.log') and isRecent('Pandoc.log')
`open pandoc-run.log` if File.file?('pandoc-run.log') and isRecent('pandoc-run.log')

0 comments on commit a86c883

Please sign in to comment.