-
-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add markdown flavor for improved math support. Closes #182
- Loading branch information
Showing
4 changed files
with
44 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#This module extends the julia markdown parser to improve compatibility with Jupyter, Pandoc etc. | ||
module WeaveMarkdown | ||
using Markdown | ||
import Markdown: @trigger, @breaking, Code, MD, withstream, startswith, LaTeX | ||
|
||
@breaking true -> | ||
function dollarmath(stream::IO, block::MD) | ||
withstream(stream) do | ||
str = Markdown.startswith(stream, r"^\$\$$"m) | ||
isempty(str) && return false | ||
trailing = strip(readline(stream)) | ||
buffer = IOBuffer() | ||
while !eof(stream) | ||
line_start = position(stream) | ||
estr = Markdown.startswith(stream, r"^\$\$$"m) | ||
if !isempty(estr) | ||
estr = Markdown.startswith(stream, r"^\$\$$"m) | ||
if isempty(estr) | ||
push!(block, LaTeX(String(take!(buffer)) |> chomp)) | ||
end | ||
return true | ||
else | ||
seek(stream, line_start) | ||
end | ||
write(buffer, readline(stream, keep=true)) | ||
end | ||
return false | ||
end | ||
end | ||
|
||
# Create own flavor and copy all the features from julia flavor | ||
Markdown.@flavor weavemd [dollarmath] | ||
weavemd.breaking = [weavemd.breaking; Markdown.julia.breaking] | ||
weavemd.regular = Markdown.julia.regular | ||
weavemd.inner = Markdown.julia.inner | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters