Skip to content

Commit

Permalink
Add support for automatically rerendering
Browse files Browse the repository at this point in the history
  • Loading branch information
SEbbaDK committed Feb 17, 2022
1 parent eae404b commit 4836959
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
result
result*
bin
lib

17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Marka - Markup/LaTeX Rendering Made Simple
`marka` is a tool for making it more convenient to work with Pandoc Markdown.
This is to support the complete replacement of normal LaTeX workflows with Markdown, without loosing any features.

## Usage
Marka consists of two tools: `marka` and `marka-combine`
The combiner is just like the preprocessor in C and is already called when using `marka` normally.
To compile a file with marka, the basic call syntax is `marka file.md`, but for day-to-day rendering it is more convenient to use the `marka -w file.md` syntax, which will automatically rerender the file when any included file is changed.

## Combination
The only way Marka Markdown differs from Pandoc Markdown, is the inclusion of the `€[./file]` construct, which recursively adds files to the project, making it more natural to include source-files or other markdown files.
This does break a bit with the convention of Markdown being readable as just a textfile, but is included because Marka Markdown is intended to replace LaTeX and many LaTeX project are too big to conveniently exist as a single file.
It also allows the inclusion of parts of source-code or other documents, which helps keep a single-source-of-truth workflow, where external data is not copied into the documentation manually, which can result in mismatches between the document version of data and the real data.

## Building
Marka is set up to build via the Crystal build tool Shards, so a simple `shards install && shards build` should produce the binaries.
There is also support for building via Nix, so a simple `nix build` will produce a derivation.
28 changes: 15 additions & 13 deletions explorer.cr
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
def explore(file : Path)
files = [] of Path
File.each_line file do |line|
match = /€\[([^]]+)\]/.match(line)
if ! match.nil?
path = Path[match[1]]
puts "Found #{path}"
if ! path.absolute?
path = (Path[file.dirname] / path).normalize
module Explorer
def self.explore(file : Path)
files = [] of Path
File.each_line file do |line|
match = /€\[([^]]+)\]/.match(line)
if ! match.nil?
path = Path[match[1]]
puts "Found #{path}"
if ! path.absolute?
path = (Path[file.dirname] / path).normalize
end
puts "Adding as #{path}"
files << path
files += explore(path)
end
puts "Adding as #{path}"
files << path
files += explore(path)
end
files
end
files
end

42 changes: 38 additions & 4 deletions marka-cli.cr
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/usr/bin/env crystal

require "option_parser"
require "inotify"

require "./marka"
require "./explorer"

marka = Marka.new

Expand Down Expand Up @@ -81,9 +83,41 @@ marka.bibliography = bib if File.exists? bib
meta = target.sibling "meta.yml"
marka.meta = meta if File.exists? meta

result = marka.render target
if !result.success?
STDERR.puts "Pandoc failed with status: #{result.exit_code}"
exit 2
def render(m, t)
result = m.render t
if !result.success?
STDERR.puts "Pandoc failed with status: #{result.exit_code}"
exit 2
end
end

render marka, target

if watch_mode
while true
files = [ target ] + Explorer.explore target

channel = Channel(Path).new

watchers = files.map do |file|
Inotify.watch file.to_s do |event|
if event.type.modify?
channel.send(file)
end
end
end

change = channel.receive

watchers.each do |w|
w.close
end

channel.close

puts "Rerendering because #{change} changed"

render marka, target
end
end

4 changes: 2 additions & 2 deletions shard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ dependencies:

targets:
marka:
main: marka.cr
main: marka-cli.cr
marka-combiner:
main: marka-combiner.cr
main: combiner-cli.cr

license: GPLv3

0 comments on commit 4836959

Please sign in to comment.