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:title>Straight quotation marks</sch:title>

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

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

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

  <sch:let name="quotes"

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

Created on , last edited on