Support escaped heredocs (#7386)

This commit is contained in:
Frank Budinsky 2020-05-22 11:12:46 -04:00 committed by GitHub
parent 3554f87c4d
commit 6581b52325
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 3 deletions

View File

@ -54,6 +54,7 @@ HEADER = """#!/bin/bash
startsnip = re.compile(r"^(\s*){{< text (syntax=)?\"?(\w+)\"? .*>}}$")
snippetid = re.compile(r"snip_id=(\w+)")
githubfile = re.compile(r"^([^@]*)(?<![A-Za-z0-9])@([\w\.\-_/]+)@([^@]*)$")
heredoc = re.compile(r"<<\s*\\?EOF")
sectionhead = re.compile(r"^##+ (.*)$")
invalidchar = re.compile(r"[^0-9a-zA-Z_]")
@ -141,7 +142,7 @@ with open(markdown, 'rt', encoding='utf-8') as mdfile:
match = githubfile.match(line)
if match:
line = match.group(1) + match.group(2) + match.group(3)
if "<<EOF" in line:
if heredoc.search(line):
multiline_cmd = True
current_snip["script"].append(line)

View File

@ -207,10 +207,12 @@ function handleCodeBlocks() {
if (cl !== "") {
let firstLineOfOutput = 0;
const lines = code.innerText.split("\n");
const heredoc = RegExp(/<<\s*\\?EOF/);
let cmd = "";
let escape = false;
let escapeUntilEOF = false;
let tmp = "";
for (let j = 0; j < lines.length; j++) {
const line = lines[j];
@ -225,14 +227,14 @@ function handleCodeBlocks() {
tmp = line.slice(2);
if (line.includes("<<EOF")) {
if (heredoc.test(line)) {
escapeUntilEOF = true;
}
} else if (escape) {
// continuation
tmp += "\n" + line;
if (line.includes("<<EOF")) {
if (heredoc.test(line)) {
escapeUntilEOF = true;
}
} else if (escapeUntilEOF) {