Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

New extension: strike through with two tildes #12

Merged
merged 10 commits into from

2 participants

@rekado

This patch adds support for strike-through markup as used on github.

Example:

This is ~~good~~ bad.
This is good bad.

@rekado

As this is an extension I could disable this by default and define EXT_STRIKE.

@jgm
Owner
@rekado

Done. The extension can be enabled with EXT_STRIKE (--strike in the executable).

@jgm
Owner

I'm reluctant to merge this yet, as it does not implement output for strikeout in all of the output formats supported...
Could you add support for the other formats?

@rekado

For LaTeX output the ulem package is required. Is print_latex_element_list the right place to put package dependencies?

For groff, a macro needs to be defined; I guess this could be output first with print_groff_mm_element_list before any element is printed. This is the macro as defined here.

.de ST
.nr ww \w'\\$1'
\Z@\v'-.25m'\l'\\n[ww]u'@\\$1
..
.
This is
.ST "a test"
an actual emergency!

It should be easy to add it to the ODF output, so I'm going to do that first.

@rekado

The odf header and footer are added in print_element_list, so I'll add any additional headers for groff and LaTeX there, too.

rekado added some commits
@rekado rekado Add strike-through support in LaTeX output 2f6a301
@rekado rekado Add strike-through support for groff output
A groff macro is defined to strike through words enclosed in pairs of
`~~` when rendering to the Postscript device. The macro doesn't yield
suitable results when rendering to any device other than Postscript.

As the macro application requires that the string be placed on its own
line, leading dots have to be escaped that result from splitting strings
like `~~Hello~~. Goodbye` after the last `~~`. Without escaping, the
groff output would be

    .ST "Hello"
    . Goodbye

leading to a failure to process ". Goodbye".
7748eca
@rekado

I've added strike-through support for groff output when rendering to the Postscript device; it should also work in edge cases.

LaTeX support has also been added.

@jgm
Owner

You might want to rewrite this patch to match the new treatment of Emph and Strong.

@rekado

Is there anything else in the way of merging this?

@jgm
Owner

Can latex \usepackage commands occur in the document body? I thought they had to be in the preamble, before \begin{document}.

@rekado

Is the output of ./markdown -x --to=latex supposed to be injected into the document section of an existing LaTeX document or is the output supposed to be processed as is? I assumed the latter.

@jgm
Owner
@rekado

Well, then it's not going to work. I don't know any (non-hackish) way to strike out text in LaTeX without adding this package, and it would have to be added to the preamble.

Do you want me to remove strike-through support for LaTeX then?

@jgm
Owner
rekado added some commits
@rekado rekado Merge branch 'upstream' into strike-extension f4c06b8
@rekado rekado add instructions for strike-through extension 575c375
@rekado rekado Do not print "\usepackage{}" line
The generated LaTeX output is understood to be the document body,
so it may not contain macros that belong into the preamble.
0100362
@rekado

I have...

  • updated the code to the latest upstream version
  • removed the \usepackage line from the LaTeX output
  • added instructions to the README (including those relating to the required LaTeX package)
@jgm jgm merged commit b6b686c into jgm:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 27, 2012
  1. @rekado
  2. @rekado
Commits on Oct 28, 2012
  1. @rekado
  2. @rekado
Commits on Nov 1, 2012
  1. @rekado

    Add strike-through support for groff output

    rekado authored
    A groff macro is defined to strike through words enclosed in pairs of
    `~~` when rendering to the Postscript device. The macro doesn't yield
    suitable results when rendering to any device other than Postscript.
    
    As the macro application requires that the string be placed on its own
    line, leading dots have to be escaped that result from splitting strings
    like `~~Hello~~. Goodbye` after the last `~~`. Without escaping, the
    groff output would be
    
        .ST "Hello"
        . Goodbye
    
    leading to a failure to process ". Goodbye".
Commits on Nov 15, 2012
  1. @rekado
  2. @rekado
Commits on Mar 29, 2013
  1. @rekado
  2. @rekado
  3. @rekado

    Do not print "\usepackage{}" line

    rekado authored
    The generated LaTeX output is understood to be the document body,
    so it may not contain macros that belong into the preamble.
This page is out of date. Refresh to see the latest.
View
7 README.markdown
@@ -134,6 +134,12 @@ The `--smart` extension provides "smart quotes", dashes, and ellipses.
The `--notes` extension provides a footnote syntax like that of
Pandoc or PHP Markdown Extra.
+The `--strike` extension provides a strike-through syntax like that of
+Redcarpet. For strike-through support in LaTeX documents the `sout`
+macro from the `ulem` package is used. Add
+`\usepackage[normalem]{ulem}` to your document's preamble to load it.
+
+
Using the library
=================
@@ -160,6 +166,7 @@ bitwise `&` operator and the following constants:
- `EXT_NOTES` turns on footnote syntax. [Pandoc's footnote syntax][] is used here.
- `EXT_FILTER_HTML` filters out raw HTML (except for styles).
- `EXT_FILTER_STYLES` filters out styles in HTML.
+ - `EXT_STRIKE` turns on strike-through syntax.
[Pandoc's footnote syntax]: http://johnmacfarlane.net/pandoc/README.html#footnotes
View
8 markdown.c
@@ -71,6 +71,7 @@ int main(int argc, char * argv[]) {
static gboolean opt_notes = FALSE;
static gboolean opt_filter_html = FALSE;
static gboolean opt_filter_styles = FALSE;
+ static gboolean opt_strike = FALSE;
static gboolean opt_allext = FALSE;
static GOptionEntry entries[] =
@@ -87,8 +88,9 @@ int main(int argc, char * argv[]) {
/* Options to active syntax extensions. These appear separately in --help. */
static GOptionEntry ext_entries[] =
{
- { "smart", 0, 0, G_OPTION_ARG_NONE, &opt_smart, "use smart typography extension", NULL },
- { "notes", 0, 0, G_OPTION_ARG_NONE, &opt_notes, "use notes extension", NULL },
+ { "smart", 0, 0, G_OPTION_ARG_NONE, &opt_smart, "use smart typography extension", NULL },
+ { "notes", 0, 0, G_OPTION_ARG_NONE, &opt_notes, "use notes extension", NULL },
+ { "strike", 0, 0, G_OPTION_ARG_NONE, &opt_strike, "use strike-through extension", NULL },
{ NULL }
};
@@ -127,6 +129,8 @@ int main(int argc, char * argv[]) {
extensions = extensions | EXT_FILTER_HTML;
if (opt_filter_styles)
extensions = extensions | EXT_FILTER_STYLES;
+ if (opt_strike)
+ extensions = extensions | EXT_STRIKE;
if (opt_to == NULL)
output_format = HTML_FORMAT;
View
3  markdown_lib.h
@@ -9,7 +9,8 @@ enum markdown_extensions {
EXT_SMART = 0x01,
EXT_NOTES = 0x02,
EXT_FILTER_HTML = 0x04,
- EXT_FILTER_STYLES = 0x08
+ EXT_FILTER_STYLES = 0x08,
+ EXT_STRIKE = 0x10
};
enum markdown_formats {
View
32 markdown_output.c
@@ -212,6 +212,11 @@ static void print_html_element(GString *out, element *elt, bool obfuscate) {
print_html_element_list(out, elt->children, obfuscate);
g_string_append_printf(out, "</strong>");
break;
+ case STRIKE:
+ g_string_append_printf(out, "<del>");
+ print_html_element_list(out, elt->children, obfuscate);
+ g_string_append_printf(out, "</del>");
+ break;
case LIST:
print_html_element_list(out, elt->children, obfuscate);
break;
@@ -444,6 +449,11 @@ static void print_latex_element(GString *out, element *elt) {
print_latex_element_list(out, elt->children);
g_string_append_printf(out, "}");
break;
+ case STRIKE:
+ g_string_append_printf(out, "\\sout{");
+ print_latex_element_list(out, elt->children);
+ g_string_append_printf(out, "}");
+ break;
case LIST:
print_latex_element_list(out, elt->children);
break;
@@ -558,6 +568,12 @@ static bool in_list_item = false; /* True if we're parsing contents of a list it
/* print_groff_string - print string, escaping for groff */
static void print_groff_string(GString *out, char *str) {
+ /* escape dots if it is the first character */
+ if (*str == '.') {
+ g_string_append_printf(out, "\\[char46]");
+ str++;
+ }
+
while (*str != '\0') {
switch (*str) {
case '\\':
@@ -652,6 +668,12 @@ static void print_groff_mm_element(GString *out, element *elt, int count) {
g_string_append_printf(out, "\\fR");
padded = 0;
break;
+ case STRIKE:
+ g_string_append_printf(out, "\\c\n.ST \"");
+ print_groff_mm_element_list(out, elt->children);
+ g_string_append_printf(out, "\"");
+ pad(out, 1);
+ break;
case LIST:
print_groff_mm_element_list(out, elt->children);
padded = 0;
@@ -948,6 +970,12 @@ static void print_odf_element(GString *out, element *elt) {
print_odf_element_list(out, elt->children);
g_string_append_printf(out, "</text:span>");
break;
+ case STRIKE:
+ g_string_append_printf(out,
+ "<text:span text:style-name=\"StrikeThrough\">");
+ print_odf_element_list(out, elt->children);
+ g_string_append_printf(out, "</text:span>");
+ break;
case LIST:
print_odf_element_list(out, elt->children);
break;
@@ -1106,6 +1134,10 @@ void print_element_list(GString *out, element *elt, int format, int exts) {
print_latex_element_list(out, elt);
break;
case GROFF_MM_FORMAT:
+ if (extensions & EXT_STRIKE) {
+ g_string_append_printf(out,
+ ".de ST\n.nr width \\w'\\\\$1'\n\\Z@\\v'-.25m'\\l'\\\\n[width]u'@\\\\$1\\c\n..\n.\n");
+ }
print_groff_mm_element_list(out, elt);
break;
case ODF_FORMAT:
View
10 markdown_parser.leg
@@ -424,6 +424,7 @@ Inline = Str
| Space
| Strong
| Emph
+ | Strike
| Image
| Link
| NoteReference
@@ -511,6 +512,13 @@ StrongUl = "__" !Whitespace
"__"
{ $$ = mk_list(STRONG, a); }
+Strike = &{ extension(EXT_STRIKE) }
+ "~~" !Whitespace
+ a:StartList
+ ( !"~~" b:Inline { a = cons(b, a); })+
+ "~~"
+ { $$ = mk_list(STRIKE, a); }
+
Image = '!' ( ExplicitLink | ReferenceLink )
{ if ($$->key == LINK) {
$$->key = IMAGE;
@@ -650,7 +658,7 @@ Nonspacechar = !Spacechar !Newline .
Newline = '\n' | '\r' '\n'?
Sp = Spacechar*
Spnl = Sp (Newline Sp)?
-SpecialChar = '*' | '_' | '`' | '&' | '[' | ']' | '(' | ')' | '<' | '!' | '#' | '\\' | '\'' | '"' | ExtendedSpecialChar
+SpecialChar = '~' | '*' | '_' | '`' | '&' | '[' | ']' | '(' | ')' | '<' | '!' | '#' | '\\' | '\'' | '"' | ExtendedSpecialChar
NormalChar = !( SpecialChar | Spacechar | Newline ) .
Alphanumeric = [0-9A-Za-z] | '\200' | '\201' | '\202' | '\203' | '\204' | '\205' | '\206' | '\207' | '\210' | '\211' | '\212' | '\213' | '\214' | '\215' | '\216' | '\217' | '\220' | '\221' | '\222' | '\223' | '\224' | '\225' | '\226' | '\227' | '\230' | '\231' | '\232' | '\233' | '\234' | '\235' | '\236' | '\237' | '\240' | '\241' | '\242' | '\243' | '\244' | '\245' | '\246' | '\247' | '\250' | '\251' | '\252' | '\253' | '\254' | '\255' | '\256' | '\257' | '\260' | '\261' | '\262' | '\263' | '\264' | '\265' | '\266' | '\267' | '\270' | '\271' | '\272' | '\273' | '\274' | '\275' | '\276' | '\277' | '\300' | '\301' | '\302' | '\303' | '\304' | '\305' | '\306' | '\307' | '\310' | '\311' | '\312' | '\313' | '\314' | '\315' | '\316' | '\317' | '\320' | '\321' | '\322' | '\323' | '\324' | '\325' | '\326' | '\327' | '\330' | '\331' | '\332' | '\333' | '\334' | '\335' | '\336' | '\337' | '\340' | '\341' | '\342' | '\343' | '\344' | '\345' | '\346' | '\347' | '\350' | '\351' | '\352' | '\353' | '\354' | '\355' | '\356' | '\357' | '\360' | '\361' | '\362' | '\363' | '\364' | '\365' | '\366' | '\367' | '\370' | '\371' | '\372' | '\373' | '\374' | '\375' | '\376' | '\377'
AlphanumericAscii = [A-Za-z0-9]
View
1  markdown_peg.h
@@ -38,6 +38,7 @@ enum keys { LIST, /* A generic list of values. For ordered and bullet lists,
HTML,
EMPH,
STRONG,
+ STRIKE,
PLAIN,
PARA,
LISTITEM,
View
3  odf.c
@@ -144,6 +144,9 @@ void print_odf_header(GString *out){
" <style:text-properties fo:font-weight=\"bold\" style:font-weight-asian=\"bold\"\n" \
" style:font-weight-complex=\"bold\"/>\n" \
" </style:style>\n" \
+ " <style:style style:name=\"StrikeThrough\" style:family=\"text\">\n" \
+ " <style:text-properties style:text-line-through-style=\"solid\"/>\n" \
+ " </style:style>\n" \
"<style:style style:name=\"MMD-Table\" style:family=\"paragraph\" style:parent-style-name=\"Standard\">\n" \
" <style:paragraph-properties fo:margin-top=\"0in\" fo:margin-bottom=\"0.05in\"/>\n" \
"</style:style>\n" \
Something went wrong with that request. Please try again.