-
Notifications
You must be signed in to change notification settings - Fork 1
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
What is the idiomatic way to extend the module? #1
Comments
Hi Gunnar, For now this module is not extensible from the outside. But for this particular use case I was planning to extend the inline_delimiters option so that instead of mapping delimiters to tag names, delimiters could also be mapped to class names which would result in a span created with this class. You could use any symbol (including any unicode symbol) to trigger this behaviour. Would this work for your use case? Mathias |
I think it would work. In the current situation, I don't need classes, but they don't bother me either. What mechanism do you see for delimiter<->class mapping? Another use case I am looking extending for is mapping inner links: I use markup like So if I can't extend the module I use some preprocessor and everything is still fine. Just looking which way to go. Thank you! |
Well, if you just need a span without any class, this is already supported through the inline_modifiers option that you can pass either on the command line or programmatically depending on the interface that you are using. The option itself is not documented currently (I'll fix that) but, meanwhile, you can look at the tests in t/400-opt-inline_delimiters.t to see how to set it. Regarding you links question, what your want sounds like collapsed reference link, but where the definition would not be in the document itself, right? In that case I can trivially add an option to specify a set of predefined link references that can be used in a document. Would that work for you? |
Yes, the As for the inner links part: the converting could benefit from some possible pre- or postprocessing callback. In my case, I need to make database calls to resolve my links. Callbacks would add simple extendability to the converting process. But this is simply manageable in the program flow anyway. Thank you for your great work and prompt responses! |
Can you query your database to collect all the possible links in advance or do you need to do that when you see a link reference or after all the link references have been seen? (by the way, I have pushed a new version with some documentation for the |
Querieng beforehand is not an option, possible ID-s are hundreds of thousands but some of these are needed in just for ~5% of cases. Or something like that. So accessing the database is certainly better only on a need basis. |
Ok, I have just pushed a new version (1.06) that adds a Let me know if this works for your use case. I would also be interested in knowing what it is that you want to use this module for if you can share some details. |
Hi! I had no time to test your new version so far. Today I made it.
Background: for now we have some quasi-HTML product descriptions, but for better manageability, I'd like to convert them into markdown. These descriptions contain many inner links in the form of [123], [i:123] or [k:123] which are converted on the fly onto correct links. I made a simple test script (which also gives some warnings) if you have time to look into that. Real output is best seen on our old web (in Estonian): https://villu.raamatukoi.ee/cgi-bin/raamat?287256 Thank you!
|
Adding support for setting the link text in the hook is easy and I can do that (it’s not there because you can’t set the link text using the normal link reference mechanism). Regarding more flexible hook, can you provide other scenarios where you would need them? This can be added but there are a couple of issues:
But if you can provide a couple of example of use-case for a more generic hook I can see how they could be exposed. |
Fyi I pushed a new version where the hook can also set the link content. |
Maybe this is not a good idea, but how I see a more generic approach is through adding pre- or postprocessing to the whole MD string/document. For example, in the same case: I need to programmatically add link text too. One more generic way would be if I in preprocessing phase substitute my specific In my view, this processing works as a hook, which gets the whole md-string as input and should return it after processing. I mean, there may be a need to expand MD for someone's needs. For example, you may need to add some metadata. You may need to parse existing metadata somehow. Or process some specific notation. Thank you for your work! |
If you want to process the input markdown string, why do you prefer doing this as a hook inside |
I don't know. My point is worn so thin already, I can't see it even myself. Thank you for your time and great work! |
Hi!
It is so good to see a fresh module for MD processing.
I need to extend MD syntax a bit for my own needs. For example, I need to define
<span>
-blocks inside some block level elements. MD standard syntax does not have tools for this occasion.What is the best way to extend
Markdown::Perl
Wbr,
Gunnar
The text was updated successfully, but these errors were encountered: