Skip to content

Commit 55e3d9f

Browse files
committed
render inside headers added
1 parent 9a12d5b commit 55e3d9f

File tree

5 files changed

+16
-7
lines changed

5 files changed

+16
-7
lines changed

src/Markdown.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ renderElement element = case element of
1717
LineBreak -> T.pack "<br />\n"
1818
Header level text id ->
1919
T.concat
20-
[T.pack "<h", T.pack (show level), T.pack " id=\"", id, T.pack "\">", escapeHtml text, T.pack "</h", T.pack (show level), T.pack ">\n"]
20+
[T.pack "<h", T.pack (show level), T.pack " id=\"", id, T.pack "\">", T.concat (map renderListItem text), T.pack "</h", T.pack (show level), T.pack ">\n"]
2121
Bold text -> T.concat [T.pack "<strong>", escapeHtml text, T.pack "</strong>"]
2222
Italic text -> T.concat [T.pack "<em>", escapeHtml text, T.pack "</em>"]
2323
BoldItalic text -> T.concat [T.pack "<strong><em>", escapeHtml text, T.pack "</em></strong>"]

src/Parser.hs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,18 +217,21 @@ parseHeader line =
217217
text = T.strip $ T.dropWhile (== '#') line
218218
cleanText = T.strip $ T.takeWhile (/= '#') text
219219
headerId = makeHeaderId cleanText
220-
in Header level cleanText headerId
220+
mdElementsText = parseInline cleanText
221+
in Header level mdElementsText headerId
221222

222223
parseUnderlineHeader :: [Text] -> Maybe (MDElement, [Text])
223224
parseUnderlineHeader (line1 : line2 : rest)
224225
| not (T.null line1) && not (T.null line2) && T.all (== '=') (T.strip line2) =
225226
let cleanText = T.strip line1
226227
headerId = makeHeaderId cleanText
227-
in Just (Header 1 cleanText headerId, rest)
228+
mdElementsText = parseInline cleanText
229+
in Just (Header 1 mdElementsText headerId, rest)
228230
| not (T.null line1) && not (T.null line2) && T.all (== '-') (T.strip line2) =
229231
let cleanText = T.strip line1
230232
headerId = makeHeaderId cleanText
231-
in Just (Header 2 cleanText headerId, rest)
233+
mdElementsText = parseInline cleanText
234+
in Just (Header 2 mdElementsText headerId, rest)
232235
| otherwise = Nothing
233236
parseUnderlineHeader _ = Nothing
234237

src/Types.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import Data.Text (Text)
88
data MDElement
99
= Paragraph [MDElement]
1010
| PlainText Text
11-
| Header Int Text Text
11+
| Header Int [MDElement] Text
1212
| Bold Text
1313
| Italic Text
1414
| BoldItalic Text

test/output.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
Перенос с помощью тега <br />
77
Последняя строка
88
</p>
9-
<h1 id="26c6a567ef051205b8ef7476284083fd">Заголовок первого уровня</h1>
9+
<h1 id="b95e0dcefa314300fb3b1f9b7022cfed">Заголовок пер<em>вого уровня</em></h1>
1010
<h2 id="9f9a76a951506992fc919b8ae3f5ae15">Заголовок второго уровня</h2>
1111
<h3 id="bc59a8b4d2160d2f5780e2c0771df8a0">Заголовок третьего уровня</h3>
1212
<h4 id="6661f1977bd9c37260dc1ca80a1516e5">Заголовок четвёртого уровня</h4>
@@ -73,9 +73,13 @@ <h2 id="9f9a76a951506992fc919b8ae3f5ae15">Заголовок второго ур
7373
<li>Первый пункт</li>
7474
<li>Второй пункт</li>
7575
<li>Третий пункт</li>
76+
</ul>
77+
<ul>
7678
<li>Первый пункт</li>
7779
<li>Второй пункт</li>
7880
<li>Третий пункт</li>
81+
</ul>
82+
<ul>
7983
<li>Первый пункт</li>
8084
<li>Второй пункт</li>
8185
<li>Третий пункт</li>

test/simple_features.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
Перенос с помощью обратного слеша\
88
Перенос с помощью тега <br> Последняя строка
99

10-
# Заголовок первого уровня
10+
# Заголовок пер*вого уровня*
1111
## Заголовок второго уровня ##
1212
### Заголовок третьего уровня
1313
#### Заголовок четвёртого уровня #
@@ -75,9 +75,11 @@ ___
7575
* Первый пункт
7676
* Второй пункт
7777
* Третий пункт
78+
7879
- Первый пункт
7980
- Второй пункт
8081
- Третий пункт
82+
8183
+ Первый пункт
8284
+ Второй пункт
8385
+ Третий пункт

0 commit comments

Comments
 (0)