Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
| Insert | `^^text^^` | — |
| Superscript | `x^2^` | — |
| Subscript | `H~2~O` | — |
| Task lists | `- [x] done` | Rendered with XHTML-compliant attributes |
| Task lists | `- [x] done` | Rendered as native Confluence task list |
| Definition lists | `Term` / `: Definition` | — |
| Abbreviations | `*[HTML]: Hyper Text Markup Language` | ⚠️ `<abbr>` tags stripped by Confluence; degrades to plain text |
| Footnotes | `text[^1]` / `[^1]: note` | Uses Confluence anchor macros for navigation |
Expand Down
36 changes: 23 additions & 13 deletions mdfluence/confluence_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,13 @@ def __init__(
self.enable_relative_links = enable_relative_links
self.relative_links: List[RelativeLink] = list()
self._has_math = False
self._task_id = 0

def reinit(self):
self.attachments = list()
self.relative_links = list()
self._has_math = False
self._task_id = 0
self.title = None

def heading(self, text, level, **attrs):
Expand Down Expand Up @@ -163,19 +165,27 @@ def image(self, text, url, title=None):
return root_element.render()

def task_list_item(self, text, checked=False):
checkbox = (
'<input class="task-list-item-checkbox" type="checkbox" disabled="disabled"'
)
if checked:
checkbox += ' checked="checked"'
checkbox += "/>"

if text.startswith("<p>"):
text = text.replace("<p>", "<p>" + checkbox, 1)
else:
text = checkbox + text

return '<li class="task-list-item">' + text + "</li>\n"
self._task_id += 1
status = "complete" if checked else "incomplete"
# Strip wrapping <p> tags for clean task body
if text.startswith("<p>") and text.rstrip().endswith("</p>"):
text = text[3:].rstrip()[:-4]
task = ConfluenceTag("task", namespace="ac")
task_id = ConfluenceTag("task-id", namespace="ac")
task_id.text = str(self._task_id)
task_status = ConfluenceTag("task-status", namespace="ac")
task_status.text = status
task_body = ConfluenceTag("task-body", namespace="ac")
task_body.text = text
task.append(task_id)
task.append(task_status)
task.append(task_body)
return task.render()

def list(self, text, ordered, **attrs):
if "<ac:task>" in text:
return "<ac:task-list>\n" + text + "</ac:task-list>\n"
return super().list(text, ordered, **attrs)

def _confluence_anchor(self, name):
macro = self.structured_macro("anchor")
Expand Down
2 changes: 1 addition & 1 deletion test_package/unit/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
),
(
"- [ ] todo\n- [x] done\n",
"task-list-item-checkbox",
"ac:task-list",
"task_lists",
),
(
Expand Down
Loading