Vorlage:Force last punctuation: Unterschied zwischen den Versionen

Aus Open Source Ecology - Germany
Zur Navigation springen Zur Suche springen
(clean code)
(+delete)
 
(3 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 5: Zeile 5:
 
   CASES , ; : . ! ?
 
   CASES , ; : . ! ?
  
   -->{{#vardefine: punctuation|{{#if: trim-always|{{{1|}}}}}<!-- -->}}<!--
+
   -->{{#vardefine: punctuation|{{#if: trim-always|{{#switch: {{{1|}}}<!--
 +
      -->| delete=<!--
 +
      -->| #default={{{1|}}}<!--
 +
      -->}}<!-- switch end
 +
    -->}}<!--
 +
  -->}}<!--
 
   -->{{#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
 +
      -->|{{#sub: {{#var: this_text}}|0|-1}}<!--
 +
      -->|{{#var: this_text}}<!--
 +
    -->}}<!-- if
 +
 
 
     fix Wiki definition list (;) or indented text (:)
 
     fix Wiki definition list (;) or indented text (:)
 
     -->{{#ifeq: :|{{#var: punctuation}}<!--
 
     -->{{#ifeq: :|{{#var: punctuation}}<!--
Zeile 18: Zeile 31:
 
         else
 
         else
 
       -->|{{#var: punctuation}}<!--
 
       -->|{{#var: punctuation}}<!--
       -->}}<!--
+
       -->}}<!-- ifeq
     -->}}<!--
+
     -->}}<!-- ifeq
 
   -->}}<!--
 
   -->}}<!--
  -->{{#vardefine: this_text_last_character|{{#sub: {{#var: this_text}}|-1|1}}<!-- -->}}<!--
 
 
    
 
    
 
   -->{{#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}}<!--
Zeile 81: Zeile 93:
 
  <nowiki>{{</nowiki>{{PAGENAME}}<nowiki>| : |Text had a dot.}}</nowiki>
 
  <nowiki>{{</nowiki>{{PAGENAME}}<nowiki>| : |Text had a dot.}}</nowiki>
 
| {{ {{PAGENAME}}| : |Text had a dot.}}
 
| {{ {{PAGENAME}}| : |Text had a dot.}}
 +
|-
 +
|
 +
<nowiki>{{</nowiki>{{PAGENAME}}<nowiki>| : |Text had no dot or other punctuation}}</nowiki>
 +
| {{ {{PAGENAME}}| : |Text had no dot or other punctuation}}
 
|-
 
|-
 
|
 
|
Zeile 93: Zeile 109:
 
  <nowiki>{{</nowiki>{{PAGENAME}}<nowiki>| delete |Text had no final .;:!? or so … }}</nowiki>
 
  <nowiki>{{</nowiki>{{PAGENAME}}<nowiki>| delete |Text had no final .;:!? or so … }}</nowiki>
 
| {{ {{PAGENAME}}| delete |Text had no final .;:!? or so … }}
 
| {{ {{PAGENAME}}| delete |Text had no final .;:!? or so … }}
 +
|-
 +
|
 +
<nowiki>{{</nowiki>{{PAGENAME}}<nowiki>| delete |only text and no punctuation}}</nowiki>
 +
| {{ {{PAGENAME}}| delete |only text and no punctuation}}
 
|}
 
|}
  

Aktuelle Version vom 19. März 2022, 22:58 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 had no dot or other punctuation}}
Text had no dot or other punctuation:
{{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 …
{{Force last punctuation| delete |only text and no punctuation}}
only text and no punctuation

There exist also the template: remove last punctuation, which is just a wrapper to {{force last punctuation | delete |Text had a question mark?}}.

Dependencies