Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

New extension: hard wrap #15

Open
wants to merge 1 commit into from

2 participants

@rekado

Insert linebreaks inside paragraphs where the origin Markdown document
had newlines (by default, Markdown ignores these newlines). This has been
modelled after the hard_wrap extension supported by Redcarpet.

EXT_HARD_WRAP
--hardwrap

@rekado rekado New extension: hard wrap
Insert linebreaks inside paragraphs where the origin Markdown document
had newlines (by default, Markdown ignores these newlines).

EXT_HARD_WRAP
--hardwrap
3be9c07
@rekado

This is the last of my additions. I've replaced Redcarpet with (r)peg-markdown in my project. I love how easy it is to extend the grammar.

@jgm
Owner

--hardwrap is probably not the best name for this option. Usually text is called "hard wrapped" when the paragraph is broken into lines for easier reading; usually one wants these to be treated as spaces when converting. Perhaps --linebreaks would be better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 28, 2012
  1. @rekado

    New extension: hard wrap

    rekado authored
    Insert linebreaks inside paragraphs where the origin Markdown document
    had newlines (by default, Markdown ignores these newlines).
    
    EXT_HARD_WRAP
    --hardwrap
This page is out of date. Refresh to see the latest.
Showing with 9 additions and 4 deletions.
  1. +6 −2 markdown.c
  2. +2 −1  markdown_lib.h
  3. +1 −1  markdown_parser.leg
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_hardwrap = 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 },
+ { "hardwrap", 0, 0, G_OPTION_ARG_NONE, &opt_hardwrap, "respect linebreaks in paragraphs", 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_hardwrap)
+ extensions = extensions | EXT_HARD_WRAP;
if (opt_to == NULL)
output_format = HTML_FORMAT;
View
3  markdown_lib.h
@@ -6,7 +6,8 @@ enum markdown_extensions {
EXT_SMART = 0x01,
EXT_NOTES = 0x02,
EXT_FILTER_HTML = 0x04,
- EXT_FILTER_STYLES = 0x08
+ EXT_FILTER_STYLES = 0x08,
+ EXT_HARD_WRAP = 0x40
};
enum markdown_formats {
View
2  markdown_parser.leg
@@ -430,7 +430,7 @@ NormalEndline = Sp Newline !BlankLine !'>' !AtxStart
TerminalEndline = Sp Newline Eof
{ $$ = NULL; }
-LineBreak = " " NormalEndline
+LineBreak = ( " " NormalEndline | &{ extension(EXT_HARD_WRAP) } NormalEndline )
{ $$ = mk_element(LINEBREAK); }
Symbol = < SpecialChar >
Something went wrong with that request. Please try again.