Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds Renderer.default_output method for alternative output formats #20

Closed
wants to merge 6 commits into from
Closed

Conversation

bslatkin
Copy link
Contributor

The new method returns the default, empty output value for the renderer.

All renderer methods use the '+=' operator to append to this value. Default is a string so rendering HTML can build up a result string with the rendered Markdown.

Can be overridden by Renderer subclasses to be types like an empty list, allowing the renderer to create a tree-like structure to represent the document (which can then be reprocessed later into a separate format like docx or pdf).

Includes an end-to-end test. I've been using it in my own projects for about 2 weeks now.

Useful for building alternative output methods (like docx) using the Renderer class.
This is useful for using an empty list as the default output value instead of a string. This allows renderers to build their own stack of directives using Python objects. This makes it easy to convert that tree of objects into other document formats besides HTML (such as docx).
@matze
Copy link

matze commented Aug 30, 2014

👍 that would be very helpful for one of my projects. This would also make mistune a real parser and not just a string translator.

@lepture
Copy link
Owner

lepture commented Aug 30, 2014

@bslatkin @matze What you need is the BlockLexer and InlineLexer. It should not be the renderer's job.

@matze
Copy link

matze commented Aug 30, 2014

What we'd need is a real parser that outputs a tree of the Markdown structure without rendering it first. The lexers are a first step but I'd need to replicate quite a lot of the Markdown parser object to get where I want to get.

@lepture
Copy link
Owner

lepture commented Sep 4, 2014

@matze @bslatkin Thanks for the feedback. I'd like a better way to create the token tree.

@lu-zero
Copy link

lu-zero commented Sep 6, 2014

Having the ability get the parse tree as emerald-tree/elementtree would be a boon.

@lepture
Copy link
Owner

lepture commented Nov 11, 2014

It has been merged into 96edd43

Working on sprint branch. It will be available in v0.5

@lepture lepture closed this Nov 11, 2014
@bslatkin
Copy link
Contributor Author

Great! Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants