saschaleib / dokuwiki-plugin-adhoctags

A secure but flexible way to insert HTML tags into DokuWiki
GNU General Public License v2.0
1 stars 0 forks source link

Add <pre> tag #8

Closed Stikus closed 1 year ago

Stikus commented 1 year ago

Hello, due to latest DokuWiki politics I have to try not no use embed HTML on pages, but I need <pre> tag to include inline formatting in code blocks:

<html><pre><span style="background-color:#fff200">rm -rf </span><span style="background-color:#ea9999">220130</span><span style="background-color:#fff200">*_fastq4</span></pre></html> image

If you can point me another plugin with these functions - I can try to use it, but I've failed to find any.

saschaleib commented 1 year ago

Hello Stikus, the preferred way to do this in DokuWiki is to use the <code> tag, which is supported out-of-the-box and also allows for syntax formatting. Though I understand that it may not always be the first choice...

Having said that, I am already considering adding the <pre> tag to this plugin. If I know that there is an interest in it, that even becomes a priority ;-)

Stikus commented 1 year ago

Thanks for instant answer. I use <code> tag far more often, but in this specific case I need various colors inside code and cannot find any other method. In inline code, I can use combination of '' and <color>:

''swap-window -t <color /#fff200>0</color>''

image

But for code block, I cannot overcome embed HTML for now.

saschaleib commented 1 year ago

Indeed, I understand the use-case. As there are no specific attributes to be added for this tag, this should actually be quite easy to implement...

saschaleib commented 1 year ago

If you can, please try to install the latest development version. This has now support for <pre> though I have not tested it yet. I will be able to make tests only later in the day, so feedback is much welcome! :-)

saschaleib commented 1 year ago

In the end, it turned out to be a bit more complicated because of the way the <pre> tag is working in what it can contain and how it should be formatted. Let's just say, it would have been much easier to implement html4-style text only <pre> tags, but then you couldn't change the text colours...

In any case, there is a new release out now, so you can just update via the Extensions manager. Don't forget to enable the new tag in the configuration settings... :-)

Stikus commented 1 year ago

Thank you for implementation - one question about tag priority: <html><pre><span style="background-color:#fff200">rm -rf __</span><span style="background-color:#ea9999">220130</span><span style="background-color:#fff200">*_fastq4__</span></pre></html>

image

<pre><a [style=background-color:#fff200]>rm -rf __</a><a [style=background-color:#ea9999]>220130</a><a [style=background-color:#fff200]>*_fastq4__</a></pre> image

I can achieve needed result with %%__%% but is it intended? <pre><a [style=background-color:#fff200]>rm -rf %%__%%</a><a [style=background-color:#ea9999]>220130</a><a [style=background-color:#fff200]>*_fastq4%%__%%</a></pre> image

Stikus commented 1 year ago

Found another problem - quotes transtation:

<pre># test
<a [style=background-color:#fff200]>date; git pull && source test.sh && runToolOnManyVUs -B 2 --tool test -r '-v "$bamLocalDir"/:/inputs:ro -v "$currOutDir":</a><a [style=background-color:#ea9999]>/outputs</a>'</pre>

<html><pre># test
<span style="background-color:#fff200">date; git pull && source test.sh && runToolOnManyVUs -B 2 --tool test -r '-v "$bamLocalDir"/:/inputs:ro -v "$currOutDir":</span><span style="background-color:#ea9999">/outputs</span>'</pre></html>

image

As you can see - in the first example, double quotes changed to guillemets (?) due to locale settings, I think.

Stikus commented 1 year ago

@saschaleib can you give me any feedback for these issues, or should I open separate issue for them?

BTW, thanks for migration-notes, FYI you can use https://www.dokuwiki.org/plugin:batchedit for this.

saschaleib commented 1 year ago

Hi and sorry, because this was added to a closed issue I didn't notice it at first.

But there is a long and a short answer to this - well, actually two short answers and a longer one :-)

First short answer: Try adding %% around the parts that you want to have copied into the page "as is". The replacement here is done by DokuWiki, which thinks you are within regular text content and actually want to quote something.

The second short answer is that you can disable this behaviour in DokuWiki via the un-intuitively named "typography" config setting. This will, however, also remove the quotation marks replacements from all other places...

Before a longer answer I should warn you that I was in my previous life a professional typesetter and as such I have very strong opinions about the correct use of the correct typographic quotation mark symbols :-) It comes down to the issue that in the end, the HTML standard gets this wrong on a very fundamental level by having the local language (i.e. that of the current tag) determine the quotation mark symbol. DokuWiki does it slightly better by using the global site language for the replacemetns, but in the end the best approach would be to not rely on such automatisms and just type the correct symbol yourself (e.g. Alt-0147 for and Alt-0148 for , etc.).

However, while I know all these codes by heart, I don't think this will be feasible for everybody, so ... yeah, just use %% ;-)

May I howver just invite you to ask such questions, which are not directly related to the plugin in the DokuWiki Forum? There are a lot more people active there and they have a lot more insight. It would also make it easier for others who have asimilar problem later, to find the results.

Stikus commented 1 year ago

The reason for my question was tag priority. I think that due to <pre> tag is used for preformatted text, it should turn off dokuwiki manipulation with text inside (like <code> or <file> tags). That's why I've asked here and not in the forum - in my opinion, it is directly related to this plugin.

If you don't think so and current behavior is intended (e.g. not to prevent using __ as underscore inside <pre>) - it's ok, I'll try to dig into code myself and find why <code> tag turning if off but '' - not. Anyway - great thanks for plugin and answers.

saschaleib commented 1 year ago

Actually, in this case DokuWiki got it wrong: both <code> and <pre> allow what is called “phrasing content”, i.e. you can use all inline elements in their context. I understand that DokuWiki is in the process of changing that, thought, hence the new %% modifier.

The defining property of the <pre>-tag is really only that it passes whitespaces (space, newlines, etc.) through to the browser. It does not change the interpretation of any other characters.

There are some good examples of this in the W3C Specs for the pre tag, including one where <code>tags are embedded in <pre> to denote computer code – though doing so may have unexpected side effects in DokuWiki, that are unfortunately outside the control (and scope) of this plugin.