Skip to content

Commit

Permalink
fix: Fix markdown list style.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Mar 11, 2022
1 parent 0449e94 commit 107d057
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
6 changes: 6 additions & 0 deletions Example/Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
/* Begin PBXBuildFile section */
7D025D0127DB47620057979B /* MarkdownStyleGroup.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D025D0027DB47620057979B /* MarkdownStyleGroup.swift */; };
7D025D0227DB47620057979B /* MarkdownStyleGroup.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D025D0027DB47620057979B /* MarkdownStyleGroup.swift */; };
7D025D0427DBCC3A0057979B /* ListGroup.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D025D0327DBCC390057979B /* ListGroup.swift */; };
7D025D0527DBCC3A0057979B /* ListGroup.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D025D0327DBCC390057979B /* ListGroup.swift */; };
7D6033B627DAE4DD00F7B36B /* DemoList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D6033B527DAE4DD00F7B36B /* DemoList.swift */; };
7D6033B727DAE4DD00F7B36B /* DemoList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D6033B527DAE4DD00F7B36B /* DemoList.swift */; };
7D6033B927DAE5DC00F7B36B /* DemoRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D6033B827DAE5DC00F7B36B /* DemoRow.swift */; };
Expand All @@ -32,6 +34,7 @@

/* Begin PBXFileReference section */
7D025D0027DB47620057979B /* MarkdownStyleGroup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarkdownStyleGroup.swift; sourceTree = "<group>"; };
7D025D0327DBCC390057979B /* ListGroup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListGroup.swift; sourceTree = "<group>"; };
7D6033B527DAE4DD00F7B36B /* DemoList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DemoList.swift; sourceTree = "<group>"; };
7D6033B827DAE5DC00F7B36B /* DemoRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DemoRow.swift; sourceTree = "<group>"; };
7D6033BF27DAEB7E00F7B36B /* CodeGroup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CodeGroup.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -75,6 +78,7 @@
7D6033C527DAF1D900F7B36B /* BaseMarkdownGroup.swift */,
7D6033C827DB2A4A00F7B36B /* ToDoGroup.swift */,
7D025D0027DB47620057979B /* MarkdownStyleGroup.swift */,
7D025D0327DBCC390057979B /* ListGroup.swift */,
);
path = Group;
sourceTree = "<group>";
Expand Down Expand Up @@ -238,6 +242,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
7D025D0427DBCC3A0057979B /* ListGroup.swift in Sources */,
7D6033C927DB2A4A00F7B36B /* ToDoGroup.swift in Sources */,
7D025D0127DB47620057979B /* MarkdownStyleGroup.swift in Sources */,
7D6033C627DAF1D900F7B36B /* BaseMarkdownGroup.swift in Sources */,
Expand All @@ -253,6 +258,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
7D025D0527DBCC3A0057979B /* ListGroup.swift in Sources */,
7D6033CA27DB2A4B00F7B36B /* ToDoGroup.swift in Sources */,
7D025D0227DB47620057979B /* MarkdownStyleGroup.swift in Sources */,
7D6033C727DAF1D900F7B36B /* BaseMarkdownGroup.swift in Sources */,
Expand Down
5 changes: 4 additions & 1 deletion Example/Shared/DemoList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ struct DemoList: View {
DemoRow(title: "Code Block", systemImage: "slider.horizontal.below.rectangle", tag: "Code Block", selection: $selection) {
CodeGroup()
}
DemoRow(title: "ToDo", systemImage: "text.badge.checkmark", tag: "ToDo", selection: $selection) {
DemoRow(title: "ToDo", systemImage: "checklist", tag: "ToDo", selection: $selection) {
ToDoGroup()
}
DemoRow(title: "List", systemImage: "list.bullet.rectangle.portrait.fill", tag: "List", selection: $selection) {
ListGroup()
}
DemoRow(
title: "markdownStyle",
systemImage: "chevron.left.forwardslash.chevron.right",
Expand Down
43 changes: 43 additions & 0 deletions Example/Shared/Group/ListGroup.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// ListGroup.swift
// Example
//
// Created by 王楚江 on 2022/3/12.
//

import Markdown
import SwiftUI

struct ListGroup: View {
@State private var mdStr: String = """
List
===
1. James Madison
2. James Monroe
3. John Quincy Adams
---
1. 第一个列表项
- 第一个嵌套列表项
- 第二个嵌套列表项
---
100. 第一个列表项
- 第一个嵌套列表项
- 第二个嵌套列表项
---
- [x] #739
- [ ] https://github.com/octo-org/octo-repo/issues/740
- [ ] Add delight to the experience when all tasks are complete :tada:
<!-- This content will not appear in the rendered Markdown -->
"""
var body: some View {
Markdown(content: $mdStr)
}
}
10 changes: 9 additions & 1 deletion Sources/Markdown/Resources/web.bundle/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@
}
return code;
},
})
});
const renderer = {
listitem: (text, task, checked) => {
const input = typeof checked == "boolean" ? `<input type="checkbox" disabled=""${checked ? ' checked=""' : ''} class="task-list-item-checkbox">`: '';
const cls = typeof checked == "boolean" && typeof task === "boolean" ? 'class="task-list-item"' : ""
return `<li ${cls}>${input} ${(text || '').replace(/^<.*?>\s/, '')}</li>`;
}
}
marked.use({ renderer });
window.__markdown_preview_dom__ = document.getElementById('__markdown_preview__');
function markdownPreview(content) {
__markdown_preview_dom__.innerHTML = marked.parse(content);
Expand Down

0 comments on commit 107d057

Please sign in to comment.