[pmwiki-users-fr] Question about inserting "&nsbp" in html output for better typography

Petko Yotov 5ko at 5ko.fr
Mar 29 Juil 20:35:02 PDT 2025


Indeed it may be best to have markup rules do the conversions on the 
fly, while keeping your source text clean.

Sometimes the tricky part is determining where to place your custom rule 
within the markup processing sequence, relative to the other rules. Here 
it may be "inline" but more precisely "after links" where the link 
brackets would have been consumed and our rules don't interfere with 
links:

   # replace space+punctuation with  +punctuation
   Markup('_?', '>links', '/ +([?!:;])/', ' $1');

   # replace quote+space...space+quote with « ... »
   Markup('"_', '>links', '/" +(.*?) +"/', 
'« $1 »');

You can have GUIEdit buttons to insert the special typographic 
characters like angled quotes, or use normal characters and convert them 
on the fly with markup rules.

   # replace [_..._] with ⟦ ... ⟧
   Markup('[_', '>links', '/\\[_ *(.*?) *_\\]/', '⟦&nbsp$1&nbsp⟧');

   # replace []+space with □ 
   Markup('[]_', '>links', '/\\[\\] +/', '□ ');

(Make sure your config.php file is saved with the UTF-8 encoding; it 
probably is.)

Then try this in a wiki page, and check the HTML source:

* before ! before ; and before : or before ?
* " after and before "
* chaud [_ [] demander chaud ; [] coûter chaud _]


If you already have the special characters in the wiki source texts, 
here are sample markup rules to replace surrounding spaces with  

   # insert   around «...» and ⟦...⟧
   Markup('«_', '>links', '/(«|⟦) +(.*?) +(»|⟧)/', '$1 $2 $3');

   # add   after □
   Markup('□_', '>links', '/□ +/', '□ ');

Use " +" to require at least one space in the source text, for example 
if you already may have "□ " in your pages, or " *" if the space is 
not required.

Note that these last 2 rules may interfere with those above which create 
the same ⟦, ⟧. □ characters. If you enable all rules above, use '<[_' 
instead of '>links' in the last 2 so that they are processed before the 
previous ones.

Petko

-- 
If you upgrade :  https://www.pmwiki.org/Upgrades

On 19/07/2025 01:47, ABClf wrote:
> Hello,
> 
> I would like to know what would be the strategy to use for inserting
> non breakable space in the text produced by pmwiki.
> My AI supported attempts are not a success by now... Maybe because I
> don't know when the transformation rules should happen ?
> 
> In French language, non breaking space is expected
> before ! ; : ?
> after and before «  » ;
> 
> Also, in my case, I do use other signs I would like to attach to the
> term they are connected to (example with letter "x" to show the
> desired non breakable space replacement)
> chaud ⟦x□xdemander chaudx; □xcoûter chaudx⟧
> 
> I can not see if it's tricky to code or quite simple with custom 
> markup.
> 
> Last, I'm not sure I want these insertions saved in my text ; it might
> be better to ask pmwiki to do the transformation every time the page
> is requested.
> 
> Thank you,
> Gilles.
> 
> _______________________________________________
> pmwiki-users-fr mailing list
> pmwiki-users-fr at pmichaud.com
> http://www.pmichaud.com/mailman/listinfo/pmwiki-users-fr



Plus d'informations sur la liste de diffusion pmwiki-users-fr