Skip to content

Commit

Permalink
feat: change async to sync processors
Browse files Browse the repository at this point in the history
  • Loading branch information
robertu7 committed Apr 18, 2023
1 parent c62e5eb commit 972081e
Show file tree
Hide file tree
Showing 12 changed files with 247 additions and 260 deletions.
2 changes: 1 addition & 1 deletion benchmark/html2md.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ for (let filename of filenames) {
htmls[filename] = html
adds.push(
add(`~${filename.split('.')[0]} characters`, async () => {
await html2md(htmls[filename])
html2md(htmls[filename])
})
)
}
Expand Down
2 changes: 1 addition & 1 deletion benchmark/md2html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ for (let filename of filenames) {
mds[filename] = md
adds.push(
add(`~${filename.split('.')[0]} characters`, async () => {
await md2html(mds[filename])
md2html(mds[filename])
})
)
}
Expand Down
4 changes: 2 additions & 2 deletions bin/build-examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const htmlDir = path.resolve('./examples/html')
const html = fs.readFileSync(path.resolve(originalDir, filename), 'utf-8')
fs.writeFileSync(
path.resolve(markdownDir, filename.replace('.html', '.md')),
await html2md(html),
html2md(html),
'utf-8'
)
}
Expand All @@ -25,7 +25,7 @@ const htmlDir = path.resolve('./examples/html')
const md = fs.readFileSync(path.resolve(markdownDir, filename), 'utf-8')
fs.writeFileSync(
path.resolve(htmlDir, filename.replace('.md', '.html')),
await md2html(md),
md2html(md),
'utf-8'
)
}
Expand Down
47 changes: 31 additions & 16 deletions demo/converter.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,41 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Markdown &#x3C;=&#x3E; HTML Converter </title>
<title>Markdown &#x3C;=&#x3E; HTML Converter</title>

<style>
html {
box-sizing: border-box;
font-size: 16px;
font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif,
'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol',
'Noto Color Emoji';
}

*, *:before, *:after {
*,
*:before,
*:after {
box-sizing: inherit;
}

body, h1, h2, h3, h4, h5, h6, p, ol, ul {
body,
h1,
h2,
h3,
h4,
h5,
h6,
p,
ol,
ul {
margin: 0;
padding: 0;
font-weight: normal;
}
main {
display: grid;
grid-template-columns: repeat(2,minmax(0,1fr));
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 8px;
padding: 8px;
width: 100%;
Expand All @@ -34,7 +48,8 @@
}
textarea {
font-size: inherit;
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
'Liberation Mono', 'Courier New', monospace;
padding: 16px;
margin-top: 8px;
width: 100%;
Expand Down Expand Up @@ -63,32 +78,32 @@ <h2>Markdown</h2>
</main>

<script type="module">
import { html2md, md2html } from './main.js';
import { html2md, md2html } from './index.esm.js'

const $html = document.querySelector('#html');
const $markdown = document.querySelector('#markdown');
const $html = document.querySelector('#html')
const $markdown = document.querySelector('#markdown')

$html.addEventListener('input', async (event) => {
let md = '';
let md = ''
try {
md = await html2md($html.value);
md = html2md($html.value)
console.log('[HTML -> MD] ', md)
} catch (error) {
md = String(error)
console.error(error)
}
$markdown.value = md;
});
$markdown.value = md
})
$markdown.addEventListener('input', async (event) => {
let html = '';
let html = ''
try {
html = await md2html($markdown.value);
html = md2html($markdown.value)
console.log('[MD -> HTML] ', html)
} catch (error) {
html = String(error)
console.error(error)
}
$html.value = html;
$html.value = html
})
</script>
</body>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@matters/matters-editor",
"version": "0.2.0-alpha.26",
"version": "0.2.0-alpha.27",
"description": "Editor for matters.news",
"author": "https://github.com/thematters",
"homepage": "https://github.com/thematters/matters-editor",
Expand Down
2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const plugins = [
resolve(),
commonjs(),
typescript({ tsconfig: './tsconfig.json' }),
terser(),
// terser(),
]

const makeGeneratePackageJson = (name) => {
Expand Down
4 changes: 2 additions & 2 deletions src/transformers/html2md.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const formatter = unified()
.use(remarkStrikethrough)
.use(remarkStringify, remarkStringifyOptions)

export const html2md = async (html: string): Promise<string> => {
const result = await formatter.process(html)
export const html2md = (html: string): string => {
const result = formatter.processSync(html)
return String(result)
}
Loading

0 comments on commit 972081e

Please sign in to comment.