Class | RubyPants |
In: |
lib/rubypants.rb
|
Parent: | String |
DOUBLE_DASH | = | n_of(2, '-') |
TRIPLE_DASH | = | n_of(3, '-') |
Create a new RubyPants instance with the text in string.
Allowed elements in the options array:
0 : | do nothing |
1 : | enable all, using only em-dash shortcuts |
2 : | enable all, using old school en- and em-dash shortcuts (default) |
3 : | enable all, using inverted old school en and em-dash shortcuts |
-1 : | stupefy (translate HTML entities to their ASCII-counterparts) |
If you don‘t like any of these defaults, you can pass symbols to change RubyPants’ behavior:
:quotes : | quotes |
:backticks : | backtick quotes (``double’’ only) |
:allbackticks : | backtick quotes (``double’’ and `single’) |
:dashes : | dashes |
:oldschool : | old school dashes |
:inverted : | inverted old school dashes |
:ellipses : | ellipses |
:prevent_breaks : | use nbsp and word-joiner to avoid breaking before dashes and ellipses |
:named_entities : | used named entities instead of the default decimal entities (see below) |
:convertquotes : | convert " entities to " |
:stupefy : | translate RubyPants HTML entities to their ASCII counterparts. |
In addition, you can customize the HTML entities that will be injected by passing in a hash for the final argument. The defaults for these entities are as follows:
:single_left_quote : | &8216; |
:double_left_quote : | &8220; |
:single_right_quote : | &8217; |
:double_right_quote : | &8221; |
:em_dash : | &8212; |
:en_dash : | &8211; |
:ellipsis : | &8230; |
:non_breaking_space : | |
:word_joiner : | &8288; |
If the :named_entities option is used, the default entities are as follows:
:single_left_quote : | ‘ |
:double_left_quote : | “ |
:single_right_quote : | ’ |
:double_right_quote : | ” |
:em_dash : | — |
:en_dash : | – |
:ellipsis : | … |
:non_breaking_space : | |
:word_joiner : | &8288; |
If the :character_entities option is used, RubyPants will emit Unicode characters directly, rather than HTML entities. By default this excludes the space characters (non-breaking space and word-joiner). To additionally emit Unicode space characters, use the :character_spaces option.
Return str replacing all patt with repl. If prevent_breaks is true, then replace spaces preceding patt with a non-breaking space, and if there are no spaces, then insert a word-joiner.
Return the string, with "``backticks’’"-style single quotes translated into HTML curly quote entities.
Return the string, with each instance of "—" translated to an em-dash HTML entity.
Return the string, with each instance of "—" translated to an em-dash HTML entity, and each "—" translated to an en-dash HTML entity. Two reasons why: First, unlike the en- and em-dash syntax supported by educate_dashes_oldschool, it‘s compatible with existing entries written before SmartyPants 1.1, back when "—" was only used for em-dashes. Second, em-dashes are more common than en-dashes, and so it sort of makes sense that the shortcut should be shorter to type. (Thanks to Aaron Swartz for the idea.)
Return the string, with each instance of "…" translated to an ellipsis HTML entity. Also converts the case where there are spaces between the dots.
Return the string, with "`backticks‘"-style single quotes translated into HTML curly quote entities.
Return the string, with after processing the following backslash escape sequences. This is useful if you want to force a "dumb" quote or other character to appear.
Escaped are:
\\ \" \' \. \- \`
Return an array of the tokens comprising the string. Each token is either a tag (possibly with nested, tags contained therein, such as <a href="<MTFoo>">, or a run of text between tags. Each element of the array is a two-element array; the first is either :tag or :text; the second is the actual value.
Based on the _tokenize() subroutine from Brad Choate‘s MTRegex plugin. <www.bradchoate.com/past/mtregex.php>
This is actually the easier variant using tag_soup, as used by Chad Miller in the Python port of SmartyPants.