Comments (6)
Cool thank you! I'll use your trick
from commonmark.jl.
That fix with be tagged shortly: 438032d.
I'll note here that I'd regard what I used to make that trick work can be regarded as public interface and won't be disappearing at random. The previous trick with push!
was definitely "doing bad things".
from commonmark.jl.
be able to ignore the conversion of indented blocks
The spec does bake-in a little bit with regards to indentation as far as I know, but on trying to disable indented code it doesn't appear to break much. So might be possible to achieve that fairly easily.
julia> p = CommonMark.Parser();
julia> text =
"""
indented
"""
" indented\n"
julia> ast = CommonMark.parse(p, text)
Node(CommonMark.Document)
julia> CommonMark.ast_dump(ast)
Document
CodeBlock
"indented\n"
julia> pop!(p.block_starts)
indented_code_block (generic function with 1 method)
julia> ast = CommonMark.parse(p, text)
Node(CommonMark.Document)
julia> CommonMark.ast_dump(ast)
Document
Paragraph
Text
"indented"
Whether disabling it causes odd behaviour elsewhere I couldn't say for certain just yet. Would be worth trying out though.
I would absolutely love to get rid of indented code blocks completely from the syntax, but alas that's never going to be a realistic goal, it makes parsing quite a bit more complex than it needs to be. https://johnmacfarlane.net/beyond-markdown.html was good reading while putting this package together.
(minor thing)
{{...}}
are converted by the Markdown module into html entities
Those aren't converted. I thought for a moment that I might have implemented that wrong, but babelmark doesn't either if I'm not mistaken.
If those are the things you'd need to get going then you might have some success, hopefully!
from commonmark.jl.
Thanks for the code, awesome I look forward to trying this out over the weekend :)
from commonmark.jl.
Sorry for briefly re-opening this, the trick you suggested does not work anymore but this:
CommonMark.indented_code_block(::CommonMark.Parser, ::CommonMark.Node) = 0
seems to work fine. It preserves base markdown formatting that happens in the indentation for instance:
julia> p = CommonMark.Parser();
julia> t = """
ab **and**
cd
ef **gh**
foo `bb`
bar
end"""
"ab **and**\n\n cd\n ef **gh**\n foo `bb`\n bar\n\nend"
julia> CommonMark.ast_dump(p(t))
Document
Paragraph
Text
"ab "
Strong
Text
"and"
Paragraph
Text
"cd"
SoftBreak
""
Text
"ef "
Strong
Text
"gh"
SoftBreak
""
Text
"foo "
Code
"bb"
SoftBreak
""
Text
"bar"
Paragraph
Text
"end"
apart from the fact that it's a dirty trick, do you see anything that could go terribly wrong from the CommonMark.jl perspective if I use this? thanks!
from commonmark.jl.
Couldn't say with any certainty whether that will do anything terribly bad, worth trying it out, though parsing CM can be pretty weird at times. You can avoid the type piracy on that method (I assume you're redefining it within the REPL (and Franklin)? by doing something like the following:
struct SkipIndented end
block_rule(::SkipIndented) = Rule((p, c) -> 0, 8, "")
julia> p = enable!(disable!(Parser(), IndentedCodeBlockRule()), SkipIndented())
Parser(Node(CommonMark.Document))
This swaps out the indented block parser with your definition without the piracy. (I was surprised that it didn't actually break anything at all.)
julia> CommonMark.ast_dump(p(t))
Document
Paragraph
Text
"ab "
Strong
Text
"and"
Paragraph
Text
"cd"
SoftBreak
""
Text
"ef "
Strong
Text
"gh"
SoftBreak
""
Text
"foo "
Code
"bb"
SoftBreak
""
Text
"bar"
Paragraph
Text
"end"
This needs a tiny patch to CM, since there's a bug in disable!
that this uncovered (which I'll push tomorrow):
diff --git a/src/parsers/rules.jl b/src/parsers/rules.jl
index a20a582..2626c3e 100644
--- a/src/parsers/rules.jl
+++ b/src/parsers/rules.jl
@@ -50,7 +50,7 @@ function disable!(p::AbstractParser, rules::Union{Tuple, Vector})
empty!(p.inline_parser.inline_parsers)
empty!(p.inline_parser.modifiers)
filter!(f -> f ∉ rules, p.rules)
- return enable!(p, p.rules)
+ return enable!(p, copy(p.rules))
end
disable!(p::AbstractParser, rule) = disable!(p, [rule])
from commonmark.jl.
Related Issues (20)
- Lists (again), conversion to LaTeX HOT 2
- Clash between TableRule and IndentedCodeBlockRule HOT 2
- Problem testing `JuliaInterpreter` on Juno/Atom HOT 1
- `@cm_str` inside list comprehension
- Interpolate a vector of items HOT 2
- HypertextLiteral.jl + CommonMark.jl = 🤯 HOT 9
- Julia 1.0: no method matching get!(::getfield(CommonMark, Symbol("##106#108")), ::IdDict{CommonMark.Node,Dict{String,Int64}}, ::CommonMark.Node) HOT 2
- Content inside `<script>` inside paragraph HOT 5
- Tables fail when there are spaces between column definitions and pipes
- Keep reference links as references HOT 6
- Separate package for Markdown AST HOT 4
- Indentation within HTML block with empty lines HOT 1
- Markdown printing adds unwanted newlines HOT 1
- Table parsing fail for some unicode identifiers HOT 1
- Duplicate rules when enabling/disabling rules HOT 1
- Disabling LinkRule (but not ImageRule) does not disable link parsing HOT 1
- Error handling multi unicode text HOT 5
- Some detailed code issues HOT 3
- `benchmark/`: simplify
- Migrate to PrecompileTools HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from commonmark.jl.