retext-project / retext

ReText: Simple but powerful editor for Markdown and reStructuredText
GNU General Public License v2.0
1.88k stars 196 forks source link

Provide a mecanism to embed Templates / Macros #545

Open xgouchet opened 3 years ago

xgouchet commented 3 years ago

Across the various documents I write using Retext, I find myself repeating some blocs of markdown.

I would really benefit from a template / macro feature. A template would have an identifier, a template content (possibly with variables). Then the user could insert a given macro from a menu or item in the menu bar. Possibly we could have a popup to fill the template variables, so that those would be filled on insertion.

E.g.:

Imagine a template named foo with content:

## %SECTION_NAME%

> %DESCRIPTION%

Upon insertion, we would prompt the user for the content of the SECTION_NAME and DESCRIPTION variables.

I'd be happy to work on this feature, just wanted to get your opinion on it first.

mitya57 commented 3 years ago

I think this will be best implemented as a Python-Markdown extension.

From a quick search, I found this one: https://github.com/qzb/markdown-jinja/. Maybe it suits your needs?

xgouchet commented 3 years ago

Thanks for this link, but it doesn't really suit my need. An extension will only apply the template on the output. Problem is I use various tools (among others pandoc) to generate different out. What I'd like is to generate markdown content from a template once. Also the goal is to be able to read the source markdown file without having to know what the template will be.

mitya57 commented 3 years ago

I try to maintain a balance between number of features and lightweightness of code (ease of maintenance).

I don’t yet fully understand the use case, but I haven’t yet seen any similar requests from other users, so this is probably a feature that won’t be widely used. So it would be best if as much as possible of it were implemented externally, e.g. as Markdown extension, export extension or even a JS script (you can use it for prompting, for example).

But I will accept a pull request if it’s compact enough and covered by tests, which will minimize the future maintenance costs.

mitya57 commented 3 years ago

Can I ask you a small off-topic question?

In ce7244ddd5298877, I adapted the translations for the change made in #528 (to avoid them being completely untranslated). But In French, the Edit menu is translated as Édition which I changed to &Édition, but I don't know if accelerators work fine with accented keys. Can you please tell me if it works? (If you will test it, run lrelease locale/retext_fr.ts to make the compiled translation file updated.)

By the way, I want to make a new release soon (tomorrow or on Tuesday). If you make a pull request for this issue then it will have to wait until the next release.

xgouchet commented 3 years ago

I understand your point, I'll try to just work with copy pastes now, and eventually I'll make a PR if I take the time to develop this.

Also I switched my locale to french, and the accelerator does work when you press Alt+É (but it doesn't work when you try with a non accented E).

mitya57 commented 3 years ago

Thank you for the quick testing! If I understand correctly, É is a single key on keyboard (i.e. does not require additional modifiers), so I assume it's fine. And sorry again for being off-topic :)