Vorlage:Force last punctuation: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
(clean code) |
(Fix this_text_with_forced_character) |
||
Zeile 7: | Zeile 7: | ||
-->{{#vardefine: punctuation|{{#if: trim-always|{{{1|}}}}}<!-- -->}}<!-- | -->{{#vardefine: punctuation|{{#if: trim-always|{{{1|}}}}}<!-- -->}}<!-- | ||
-->{{#vardefine: this_text|{{#if: trim-always|{{{2|}}}}}<!-- -->}}<!-- | -->{{#vardefine: this_text|{{#if: trim-always|{{{2|}}}}}<!-- -->}}<!-- | ||
− | -->{{#vardefine: this_text_with_forced_character|{{#sub: {{#var: this_text}}|0|-1}}<!-- | + | -->{{#vardefine: this_text_last_character|{{#sub: {{#var: this_text}}|-1|1}}<!-- -->}}<!-- |
+ | |||
+ | -->{{#vardefine: this_text_with_forced_character|{{#if:{{#pos: .;:?!{{#var: punctuation}}|{{#var: this_text_last_character}} }}<!-- | ||
+ | then | ||
+ | -->|{{#var: this_text}}<!-- | ||
+ | |||
+ | -->|{{#sub: {{#var: this_text}}|0|-1}}<!-- | ||
+ | |||
fix Wiki definition list (;) or indented text (:) | fix Wiki definition list (;) or indented text (:) | ||
− | + | -->{{#ifeq: :|{{#var: punctuation}}<!-- | |
− | |||
− | |||
− | |||
− | |||
then | then | ||
− | -->|<nowiki> | + | -->|<nowiki>:</nowiki><!-- |
else | else | ||
− | -->|{{#var: punctuation}}<!-- | + | -->|{{#ifeq: ;|{{#var: punctuation}}<!-- |
− | -->}}<!-- | + | then |
− | -->}}<!-- | + | -->|<nowiki>;</nowiki><!-- |
+ | else | ||
+ | -->|{{#var: punctuation}}<!-- | ||
+ | -->}}<!-- ifeq | ||
+ | -->}}<!-- ifeq | ||
+ | -->}}<!-- if | ||
-->}}<!-- | -->}}<!-- | ||
− | |||
-->{{#switch: {{#if: trim-always|{{{1|}}}}} | -->{{#switch: {{#if: trim-always|{{{1|}}}}} | ||
|delete=<!-- | |delete=<!-- | ||
− | -->{{#if:{{#pos: .;:?!|{{#var: this_text_last_character}} }}<!-- | + | -->{{#if:{{#pos: .;:?!{{#var: punctuation}}|{{#var: this_text_last_character}} }}<!-- |
then | then | ||
-->|{{#sub: {{#var: this_text}}|0|-1}}<!-- | -->|{{#sub: {{#var: this_text}}|0|-1}}<!-- | ||
-->|{{#var: this_text}}<!-- | -->|{{#var: this_text}}<!-- | ||
− | -->}} | + | -->}} |
|#default=<!-- | |#default=<!-- | ||
-->{{#ifeq: {{#var: this_text_last_character}}<!-- last character in 2:text -->|<!-- same as 1:punctuation -->{{#var: punctuation}}<!-- | -->{{#ifeq: {{#var: this_text_last_character}}<!-- last character in 2:text -->|<!-- same as 1:punctuation -->{{#var: punctuation}}<!-- |
Version vom 17. April 2020, 12:22 Uhr
This template checks for the last punctuation character and removes it if there should be comma (,) colon (:) semicolon (;) exclamation mark (!) question mark (?) or a dot (.). So it forces to be there one of these characters. But it can also remove the last character. Examples:
Code | Result |
---|---|
{{Force last punctuation| : |Text had a dot.}} |
Text had a dot. |
{{Force last punctuation| . |Text and question mark remains? | allow = ?! }} |
Text and question mark remains? |
{{Force last punctuation| delete |Text had a question mark? }} |
Text had a question mark |
{{Force last punctuation| delete |Text had no final .;:!? or so … }} |
Text had no final .;:!? or so … |
There exist also the template: remove last punctuation, which is just a wrapper to {{force last punctuation | delete |Text had a question mark?}}
.
Dependencies