Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#### Review fixes

- Preserved code spans containing three or more spaces when exporting Todo files to Markdown.
- Offered known tag-argument completions inside auto-closed parentheses without inserting a duplicate closing parenthesis.
- Preserved punctuation immediately before a completion or elapsed-time tag when reopening a task.
- Rejected invalid ISO calendar dates in time estimates instead of silently rolling them into another month.
Expand Down
7 changes: 6 additions & 1 deletion src/utils/markdown-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ const escapeMarkdownText = (text: string): string => text.replace(/[!-/:-@[-`{-~
const renderCodeSpan = (content: string): string => {
if (!content) return '<code></code>';

const needsPadding = (content.startsWith(' ') || content.endsWith(' ')) && !/^ +$/.test(content),
// Markdown trims a space from each end of runs longer than two spaces,
// even when the code span contains nothing but spaces.
const spacesOnly = /^ +$/.test(content),
needsPadding = spacesOnly
? content.length > 2
: content.startsWith(' ') || content.endsWith(' '),
padding = needsPadding ? ' ' : '';

return `\`${padding}${content}${padding}\``;
Expand Down
9 changes: 9 additions & 0 deletions test/markdown-export.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ describe('Todo Markdown export', () => {
expect(html).to.include('<code></code> <code> </code> <code> code </code>');
});

it('preserves code spans containing three or more spaces', () => {
const markdown = renderTodoMarkdown('Tasks', [
{ kind: 'comment', level: 0, text: '` ` ` `' },
]),
html = new MarkdownIt({ html: true }).render(markdown);

expect(html).to.include('<code> </code> <code> </code>');
});

it('preserves HTML-like text and entities in rendered Markdown', () => {
const markdown = renderTodoMarkdown('Plan <T> &copy;', [
{ kind: 'project', level: 0, text: 'Project <T> &copy;' },
Expand Down
Loading