Skip to content

Commit

Permalink
Fix markdown text styles (Issue #517)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelrsweet committed Feb 11, 2024
1 parent e6bdf4b commit eb3e99f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Changes in HTMLDOC v1.9.18

- Fixed markdown emphasized, strong, and struck-through text (Issue 517)


# Changes in HTMLDOC v1.9.17

- Added new `--pre-indent` option to control indentation of pre-formatted text
Expand Down
29 changes: 22 additions & 7 deletions htmldoc/markdown.cxx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Markdown parsing definitions for HTMLDOC, a HTML document processing program.
*
* Copyright © 2017-2020 by Michael R Sweet.
* Copyright © 2017-2024 by Michael R Sweet.
*
* This program is free software. Distribution and use rights are outlined in
* the file "COPYING".
Expand Down Expand Up @@ -271,32 +271,42 @@ add_leaf(tree_t *html, /* I - Parent HTML node */
*text, /* Text to write */
*url; /* URL to write */
int whitespace; /* Whitespace before text? */
unsigned style; /* Style for node */
unsigned typeface; /* Typeface for node */
unsigned strikethrough; /* Struck-through text? */


text = get_text((uchar *)mmdGetText(node));
url = (uchar *)mmdGetURL(node);
whitespace = mmdGetWhitespace(node);
style = html->style;
strikethrough = html->strikethrough;
typeface = html->typeface;
text = get_text((uchar *)mmdGetText(node));
url = (uchar *)mmdGetURL(node);
whitespace = mmdGetWhitespace(node);

switch (mmdGetType(node))
{
case MMD_TYPE_EMPHASIZED_TEXT :
element = MARKUP_EM;
style = STYLE_ITALIC;
break;

case MMD_TYPE_STRONG_TEXT :
element = MARKUP_STRONG;
style = STYLE_BOLD;
break;

case MMD_TYPE_STRUCK_TEXT :
element = MARKUP_DEL;
element = MARKUP_DEL;
strikethrough = 1;
break;

case MMD_TYPE_LINKED_TEXT :
element = MARKUP_A;
break;

case MMD_TYPE_CODE_TEXT :
element = MARKUP_CODE;
element = MARKUP_CODE;
typeface = _htmlBodyFont >= TYPE_MONOSPACE ? TYPE_MONOSPACE : TYPE_COURIER;
break;

case MMD_TYPE_IMAGE :
Expand Down Expand Up @@ -326,7 +336,9 @@ add_leaf(tree_t *html, /* I - Parent HTML node */
}

if (element == MARKUP_NONE)
{
parent = html;
}
else if ((parent = html->last_child) == NULL || parent->markup != element)
{
if (whitespace)
Expand All @@ -335,7 +347,10 @@ add_leaf(tree_t *html, /* I - Parent HTML node */
whitespace = 0;
}

parent = htmlAddTree(html, element, NULL);
parent = htmlAddTree(html, element, NULL);
parent->style = style;
parent->strikethrough = strikethrough;
parent->typeface = typeface;

if (element == MARKUP_A && url)
{
Expand Down

0 comments on commit eb3e99f

Please sign in to comment.