-
Notifications
You must be signed in to change notification settings - Fork 52
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
implement placeholder replacement #46
base: master
Are you sure you want to change the base?
Conversation
* implement argument "--replace-placeholders-file" to define YAML file which configures replacements for placeholder strings in MD files Signed-off-by: Andreas Ulm <andreas.ulm@skaylink.com>
I feel very conflicted about this, because I appreciate the use cases this solves but I don't particularly like the way it was implemented. Mistune (even on the old version I'm using) supports custom lexers to parse custom grammars, but your implementation is sidestepping all of that and going a roundabout way to do the replacements outside of the normal flow. |
I was conflicted for the same reason and invested about a day to change the implementation using those custom lexers. The problems I faced were the following:
Because of those problems I decided to start with my first implementation as PR and hope for such a discussion. :)
As you are okay with the feature itself, I'll test again an implementation based on custom lexers. |
Hello :) Were you able to work on this at all? Just checking. |
I'm still trying to figure out a nice pythonic way to implement the feature by using mistune. I had a short look into mistune v2 but the change is to much for me to oversee and integrate thus I'm working on the function overwrite. |
I am looking for exactly this sort of feature - I have gitlab markdown documents (in code) and I am setting up a process to update confluence when those docs change. The docs have a lot of "widgets" like I can rewrite the urls in a preprocessing step, but I can not figure out how to directly include a confluence macro in the final document before it's uploaded. I assume the library can help me here but a general purpose solution like this would be nice to have. |
Unfortunately I don't have access to systems required to test this implementation anymore. Thus I cannot further work on this feature. |
@jblotus Have you tried simply including the Confluence tags in your documents and seeing if they make it through untouched? |
This PR implements the argument "--replace-placeholders-file".
It allows to specify a YAML structured file that defines a mapping of strings/regex and their replacements.
Using this file you can define that some text used in markdown files (e.g. Hugo Shortcodes is replaced by text or Confluence Macros.
The added sample_placeholders.yaml show some examples.
The syntax of the file allows specifying text or regex as key.
For regex groups are supported and can be backreferenced (see example 3).
The
additions
key is a list of strings that are added without modification (e.g. example 3).For this feature I added a check to
ConfluenceTag.render()
thuschild.render()
is only called whenchild
is of typeConfluenceTag
.I did not implement the replacements within
ConfluenceRenderer
as it seemed impossible to extend the default functions ofmistune.Renderer
in a way that any custom configurable text will be replaced.Instead I'm using
re.sub()
as this implementation allow to store all "magic" for a replacement within the configuration file.