Skip to main content

 Sample Code

Some code samples

Validating quotation marks

In good typography, curly quotes are used in text:

  • the left (or opening) single quote (‘),
  • the right (or closing) single quote (’),
  • the left (or opening) double quote (“),
  • and the right (or closing) double quote (”).

But in software code, straight quotes are important and must be replaced by curly quotes. The following example lets you validate your content to ensure that curly quotes and straight quotes are used in the right context.

Schematron patterns

We separate Schematron patterns to ensure that the rules are evaluated independently.

The following code checks that straight quotation marks are used only in code:

<sch:pattern>
  <sch:title>Straight quotation marks</sch:title>

  <sch:rule context="fragment//*[contains(text(), '&quot;')]">
    <sch:report test="not(self::monospace|ancestor::monospace
                         |self::preformat|ancestor::preformat)">
      Found straight quotation mark (") in text.
     Use typographical quotation marks instead.
    </sch:report>
 </sch:rule>
</sch:pattern>

The following code checks that typographical quotation marks are not used in code:

<sch:pattern>
  <sch:title>Typographical quotation marks</sch:title>

  <sch:let name="quotes"
           value="'[&#x2018;&#x2019;&#x201C;&#x201D;]'"/>

  <sch:rule context="fragment//*[matches(text(), $quotes, 'm')]">
    <sch:assert test="not(self::monospace|ancestor::monospace
                         |self::preformat|ancestor::preformat)">
      Found typographical quotation mark in code.
      Use straight quotation marks instead.
    </sch:assert>
  </sch:rule>

</sch:pattern>
Created on , last edited on