Commit d931d90
src/cli.ts
@@ -217,7 +217,6 @@ export function injectGlobalRequire(origin: string) {
}
export function transformMarkdown(buf: Buffer | string): string {
- const source = buf.toString()
const output = []
const tabRe = /^( +|\t)/
const codeBlockRe =
@@ -225,7 +224,7 @@ export function transformMarkdown(buf: Buffer | string): string {
let state = 'root'
let codeBlockEnd = ''
let prevLineIsEmpty = true
- for (const line of source.split(/\r?\n/)) {
+ for (const line of buf.toString().split(/\r?\n/)) {
switch (state) {
case 'root':
if (tabRe.test(line) && prevLineIsEmpty) {
src/util.ts
@@ -277,23 +277,19 @@ export function formatCmd(cmd?: string): string {
}
function space() {
- if (/\s/.test(ch)) return space
- return root
+ return /\s/.test(ch) ? space : root
}
function word() {
- if (/[\w/.]/i.test(ch)) return word
- return root
+ return /[\w/.]/i.test(ch) ? word : root
}
function syntax() {
- if (isSyntax(ch)) return syntax
- return root
+ return isSyntax(ch) ? syntax : root
}
function dollar() {
- if (ch === "'") return str
- return root
+ return ch === "'" ? str : root
}
function str() {
@@ -311,13 +307,11 @@ export function formatCmd(cmd?: string): string {
}
function strDouble() {
- if (ch === '"') return strEnd
- return strDouble
+ return ch === '"' ? strEnd : strDouble
}
function strSingle() {
- if (ch === "'") return strEnd
- return strSingle
+ return ch === "'" ? strEnd : strSingle
}
function strEnd() {