@@ -21,10 +21,16 @@ function generateMarkdown(doc) {
21
21
// and generates files that render well on GitHub.
22
22
turndownService . use ( gfm ) ;
23
23
24
- // Special handling for emphasized code blocks (e.g.
25
- // `<code><em>1234<em></code>`). The default results in the underscores being
26
- // rendered (e.g. `_1234_`), but by inverting the tags it will emphasize the
27
- // code in the block (e.g. _`1234`_).
24
+ // Special handling for emphasized code blocks.
25
+ //
26
+ // ```html
27
+ // <code><em>1234<em></code>
28
+ // ```
29
+ //
30
+ // The default results in the underscores being rendered within the code
31
+ // block. Since the entire code block should be emphasized a simple solution
32
+ // is to just move the emphasis outside the block which appears to create the
33
+ // correct result (on GitHub at least).
28
34
turndownService . addRule ( "emphasizedCode" , {
29
35
filter : ( node ) =>
30
36
node . nodeName == "CODE" &&
@@ -36,6 +42,26 @@ function generateMarkdown(doc) {
36
42
`${ options . emDelimiter } \`${ node . innerText } \`${ options . emDelimiter } ` ,
37
43
} ) ;
38
44
45
+ // Special handling for emphasized text within code blocks.
46
+ //
47
+ // ```html
48
+ // <code>1 + 1 = <em>2</em></code>
49
+ // ```
50
+ //
51
+ // The default rendering results in the underscores being rendered, as there
52
+ // isn't a proper way to render emphasis within code blocks without resorting
53
+ // to HTML again. In this case the best solution is to drop the emphasis
54
+ // completely, rendering the content without any markup.
55
+ //
56
+ // Since the rules are applied in order this should only consider instances
57
+ // where the previous code did not make a modification.
58
+ turndownService . addRule ( "emphasisWithinCode" , {
59
+ filter : ( node ) =>
60
+ node . nodeName == "EM" &&
61
+ node . parentNode . nodeName == "CODE" ,
62
+ replacement : ( content ) => content ,
63
+ } ) ;
64
+
39
65
// Keep the spans which are used for alternate text in the puzzle description.
40
66
turndownService . keep ( [ "span" ] ) ;
41
67
0 commit comments