Skip to content

Commit

Permalink
feat: underline supported (#527)
Browse files Browse the repository at this point in the history
  • Loading branch information
akosbalasko authored Sep 17, 2023
1 parent 1b4c94d commit 3397824
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/utils/turndown-rules/underline-rule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

// Note: this rule must appear *after* use(gfm) so it can override
// turndown-plugin-gfm rule for strikethrough (which always uses single '~')
export const underlineRule = {
filter: ['u'],
replacement: (content: any) => {
return `<u>${content}</u>`
},
};
3 changes: 2 additions & 1 deletion src/utils/turndown-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { OutputFormat } from './../output-format';
import { taskListRule } from './turndown-rules/task-list-rule';
import { removeNewlines } from './remove-newlines';
import { tanaTableBlock, tanaTableColBlock, tanaTableRowBlock } from './../constants';
import { underlineRule } from './turndown-rules/underline-rule';

export const getTurndownService = (yarleOptions: YarleOptions) => {
/* istanbul ignore next */
Expand All @@ -39,7 +40,7 @@ export const getTurndownService = (yarleOptions: YarleOptions) => {
turndownService.addRule('images', imagesRule);
turndownService.addRule('list', taskListRule);
turndownService.addRule('italic', italicRule);

turndownService.addRule('underline', underlineRule);
if (yarleOptions.outputFormat === OutputFormat.LogSeqMD) {
turndownService.addRule('logseq_hr', {
filter: ['hr'],
Expand Down
16 changes: 16 additions & 0 deletions test/data/text styles.enex
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE en-export SYSTEM "http://xml.evernote.com/pub/evernote-export4.dtd">
<en-export export-date="20231017T104418Z" application="Evernote" version="10.61.10">
<note>
<title>text styles</title>
<created>20230917T104146Z</created>
<updated>20230917T104412Z</updated>
<note-attributes>
<author>akos</author>
</note-attributes>
<content>
<![CDATA[<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd"><en-note><div><u>This is an underline text</u></div><div><b>This is a bold text</b></div><div><i>This is an italic text</i></div><div><span style="--en-highlight:yellow;background-color: #ffef9e;">This is a highlighted text</span></div></en-note> ]]>
</content>
</note>
</en-export>
10 changes: 10 additions & 0 deletions test/data/text styles.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# text styles

<u>This is an underline text</u>
**This is a bold text**
_This is an italic text_
`This is a highlighted text`

Created at: 2023-09-17T11:41:46+01:00
Updated at: 2023-09-17T11:44:12+01:00

11 changes: 11 additions & 0 deletions test/yarle-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,18 @@ export const yarleTests: Array<YarleTest> = [

expectedOutputPath: `${dataFolder}link to telephone_ 202-555-0179.md`,
},
{
name: 'Note text styles',
options: {
enexSources: [ `.${testDataFolder}text styles.enex` ],
outputDir: 'out',
isMetadataNeeded: true,
useZettelIdAsFilename: false
},
testOutputPath: `notes${path.sep}text styles${path.sep}text styles.md`,

expectedOutputPath: `${dataFolder}text styles.md`,
},
{
name: 'Note with zettelkastel id - use as filename',
options: {
Expand Down

0 comments on commit 3397824

Please sign in to comment.