-
Notifications
You must be signed in to change notification settings - Fork 204
Conversation
While this is a very nice feature, it's not part of the markdown spec. Maybe it should be opt in or implemented in a pluggable way? |
There is some minor out-of-spec stuff here already. |
I think it's generous to call markdown a spec anyway :P This PR doesn't currently handle duplicate heading anchors though.. |
This actually might be better as an an option on the HtmlPrinter rather than in the parser? |
Agreed! 😄 Most (all?) popular markdown implementations have moved beyond the "spec" to support things like triple-backticks (as dart-markdown does) no intra-emphasis, autolinking, etc. I like the extensions hash that redcarpet uses (notice the GitHub deep link 😉 ): markdown = Redcarpet::Markdown.new(renderer, extensions = {no_intra_emphasis: true})
markdown.render("Hello foo_bar_baz. _Bye!_")
# => "<p>Hello foo_bar_baz. <em>Bye!</em></p>" |
@dpeek thanks for the comments. I added uniqueness, which did largely take place in HtmlRenderer, and a test. You mentioned this might be better in the renderer than the parser... If I understand you correctly, this would involve putting HTML context in ast.dart (only apply to header tags, fetching the inner text, etc.). I like it in block_parser, since that is where the Elements are constructed anyway. What do you think? |
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project, in which case you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
2e679c9
to
9cf7b27
Compare
CLAs look good, thanks! |
Rebased. |
I definitely think this is useful, but I agree with @caffinatedmonkey that it's non-standard. I think this should be done as an extension, but that would imply having some general architecture around extensions, which isn't quite there yet. I am interested in doing that, but I probably won't have time for a while. TL;DR: I like this, but it will be a while before I'm in a place to land it. |
After you get the extension stuff figured out and landed, how about making this an opt-in extension? |
e23be05
to
053d715
Compare
@munificent this is ready for review now. Implemented as extensions. |
static String generateAnchorHash(Element element) => | ||
_concatenatedText(element) | ||
.toLowerCase() | ||
.replaceAll(new RegExp(r'^[^a-z]+'), '') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this redundant with the next line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line kills all leading non-alphabetical characters. The next line kills all non alphanumeric+[ _-]
characters, throughout. I don't think they're combinable.
Couple of suggestions and questions, but 👍 |
053d715
to
9ff50b1
Compare
9ff50b1
to
1d66820
Compare
Thanks @munificent ! |
…headers Adding ids to headers
I changed the (Setext)HeaderSyntax to generate an id for all headers generated, so that they can be deep-linked. This deep-linking can then also be used within a document using something like #this.