Skip to content

Commit

Permalink
Use acorn parser to parse the jsx tag for figure
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Apr 16, 2021
1 parent 69d4b92 commit abb8408
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 24 deletions.
1 change: 1 addition & 0 deletions website/docs/img
Binary file removed website/docs/img/bcc2020_img1.png
Binary file not shown.
Binary file removed website/docs/img/bcc2020_img2.png
Binary file not shown.
Binary file removed website/docs/img/bcc2020_img3.png
Binary file not shown.
Binary file removed website/docs/img/bcc2020_jbrowse_help.png
Binary file not shown.
Binary file removed website/docs/img/bcc2020_network_success.png
Binary file not shown.
Binary file removed website/docs/img/favicon.ico
Binary file not shown.
1 change: 0 additions & 1 deletion website/docs/img/logo.svg

This file was deleted.

41 changes: 18 additions & 23 deletions website/docs/tex_parser.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/* eslint-disable no-console,no-continue */
const readline = require('readline')
const acorn = require('acorn')
const jsx = require('acorn-jsx')

const rl = readline.createInterface({
input: process.stdin, // or fileStream
})

const parser = acorn.Parser.extend(jsx())
let readingHeader = false
let title = ''
let topLevel = false
let figure = ''
let caption = ''

;(async () => {
for await (const line of rl) {
Expand All @@ -33,29 +33,24 @@ let caption = ''
}
continue
}
if (line.startsWith('![]')) {
const res = line.match(/\(([^)]+)\)/)
if (res) {
figure = res[1].replace('/jb2', '..')
continue
}
}
if (figure) {
if (line.trim() !== '') {
caption += `${line} `
continue
} else {
console.log(`![${caption}](${figure})\n\n`)
figure = ''
caption = ''
continue
}
if (line.startsWith('<Figure')) {
const res = parser.parse(line, { ecmaVersion: 2020 })
const src = res.body[0].expression.openingElement.attributes.find(
attr => attr.name.name === 'src',
)
const caption = res.body[0].expression.openingElement.attributes.find(
attr => attr.name.name === 'caption',
)

// chop off leading absolute figure /
const srcval = src.value.value.slice(1)
const captionval = caption.value.value
console.log(`![${captionval}](${srcval})\n\n`)
continue
}

if (readingHeader === false) {
console.log(line)
}
}
if (figure && caption) {
console.log(`![${caption}](${figure})\n\n`)
}
})()
2 changes: 2 additions & 0 deletions website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
"@docusaurus/core": "^2.0.0-alpha.72",
"@docusaurus/preset-classic": "^2.0.0-alpha.72",
"@material-ui/core": "^4.9.13",
"acorn": "^8.1.1",
"acorn-jsx": "^5.3.1",
"clsx": "^1.1.1",
"react": "^16.8.4",
"react-dom": "^16.8.4"
Expand Down
10 changes: 10 additions & 0 deletions website/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2983,6 +2983,11 @@ accepts@~1.3.4, accepts@~1.3.5, accepts@~1.3.7:
mime-types "~2.1.24"
negotiator "0.6.2"

acorn-jsx@^5.3.1:
version "5.3.1"
resolved "https://registry.yarnpkg.com/acorn-jsx/-/acorn-jsx-5.3.1.tgz#fc8661e11b7ac1539c47dbfea2e72b3af34d267b"
integrity sha512-K0Ptm/47OKfQRpNQ2J/oIN/3QYiK6FwW+eJbILhsdxh2WTLdl+30o8aGdTbm5JbffpFFAg/g+zi1E+jvJha5ng==

acorn-walk@^8.0.0:
version "8.0.2"
resolved "https://registry.yarnpkg.com/acorn-walk/-/acorn-walk-8.0.2.tgz#d4632bfc63fd93d0f15fd05ea0e984ffd3f5a8c3"
Expand All @@ -2998,6 +3003,11 @@ acorn@^8.0.4:
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.1.0.tgz#52311fd7037ae119cbb134309e901aa46295b3fe"
integrity sha512-LWCF/Wn0nfHOmJ9rzQApGnxnvgfROzGilS8936rqN/lfcYkY9MYZzdMqN+2NJ4SlTc+m5HiSa+kNfDtI64dwUA==

acorn@^8.1.1:
version "8.1.1"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.1.1.tgz#fb0026885b9ac9f48bac1e185e4af472971149ff"
integrity sha512-xYiIVjNuqtKXMxlRMDc6mZUhXehod4a3gbZ1qRlM7icK4EbxUFNLhWoPblCvFtB2Y9CIqHP3CF/rdxLItaQv8g==

[email protected], address@^1.0.1:
version "1.1.2"
resolved "https://registry.yarnpkg.com/address/-/address-1.1.2.tgz#bf1116c9c758c51b7a933d296b72c221ed9428b6"
Expand Down

0 comments on commit abb8408

Please sign in to comment.