Skip to content

Commit

Permalink
fix: allow zero-width space as emphasis separator (#112)
Browse files Browse the repository at this point in the history
fixes #98.
  • Loading branch information
rasendubi committed May 19, 2024
1 parent 2b8e9ca commit 0e1d4b7
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/thick-mice-breathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'uniorg-parse': patch
---

Allow Zero-Width Space as emphasis separator.
17 changes: 17 additions & 0 deletions packages/uniorg-parse/src/__snapshots__/parser.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5343,3 +5343,20 @@ children:
minute: 36
end: null
`;
exports[`org/parser zero-width whitespace as emphasis separator 1`] = `
type: "org-data"
contentsBegin: 0
contentsEnd: 12
children:
- type: "paragraph"
affiliated: {}
contentsBegin: 0
contentsEnd: 12
children:
- type: "code"
value: "code"
children: []
- type: "text"
value: "​hello"
`;
11 changes: 8 additions & 3 deletions packages/uniorg-parse/src/parse-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,19 @@ export interface ParseOptions {
export const defaultOptions: ParseOptions = {
todoKeywords: ['TODO', 'DONE'],
useSubSuperscripts: true,
// Interestingly enough, zero-width space (\u200b) is not considered
// a space in unicode but is considered a space by Emacs. This is
// why we have to add \u200b explicitly after \s in the
// regex. Otherwise, the suggested use-case of adding ZWSP as a
// markup border does not work.
emphasisRegexpComponents: {
// deviates from org mode default to allow ndash, mdash, and
// quotes (’“”)
pre: '-–—\\s\\(\'’"“”\\{',
pre: '-–—\\s\u200b\\(\'’"“”\\{',
// deviates from org mode default to allow ndash, mdash, and
// quotes (’“”)
post: '-–—\\s.,:!?;\'’"“”\\)\\}\\[',
border: '\\s',
post: '-–—\\s\u200b.,:!?;\'’"“”\\)\\}\\[',
border: '\\s\u200b',
body: '.',
newline: 1,
},
Expand Down
3 changes: 3 additions & 0 deletions packages/uniorg-parse/src/parser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1127,4 +1127,7 @@ line break`
not next line`
);
});

// See https://github.com/rasendubi/uniorg/issues/98
itParses('zero-width whitespace as emphasis separator', `~code~\u200bhello`);
});

0 comments on commit 0e1d4b7

Please sign in to comment.