mirror of https://github.com/istio/istio.io.git
Support escaped heredocs (#7386)
This commit is contained in:
parent
3554f87c4d
commit
6581b52325
|
|
@ -54,6 +54,7 @@ HEADER = """#!/bin/bash
|
||||||
startsnip = re.compile(r"^(\s*){{< text (syntax=)?\"?(\w+)\"? .*>}}$")
|
startsnip = re.compile(r"^(\s*){{< text (syntax=)?\"?(\w+)\"? .*>}}$")
|
||||||
snippetid = re.compile(r"snip_id=(\w+)")
|
snippetid = re.compile(r"snip_id=(\w+)")
|
||||||
githubfile = re.compile(r"^([^@]*)(?<![A-Za-z0-9])@([\w\.\-_/]+)@([^@]*)$")
|
githubfile = re.compile(r"^([^@]*)(?<![A-Za-z0-9])@([\w\.\-_/]+)@([^@]*)$")
|
||||||
|
heredoc = re.compile(r"<<\s*\\?EOF")
|
||||||
sectionhead = re.compile(r"^##+ (.*)$")
|
sectionhead = re.compile(r"^##+ (.*)$")
|
||||||
invalidchar = re.compile(r"[^0-9a-zA-Z_]")
|
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)
|
match = githubfile.match(line)
|
||||||
if match:
|
if match:
|
||||||
line = match.group(1) + match.group(2) + match.group(3)
|
line = match.group(1) + match.group(2) + match.group(3)
|
||||||
if "<<EOF" in line:
|
if heredoc.search(line):
|
||||||
multiline_cmd = True
|
multiline_cmd = True
|
||||||
current_snip["script"].append(line)
|
current_snip["script"].append(line)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -207,10 +207,12 @@ function handleCodeBlocks() {
|
||||||
if (cl !== "") {
|
if (cl !== "") {
|
||||||
let firstLineOfOutput = 0;
|
let firstLineOfOutput = 0;
|
||||||
const lines = code.innerText.split("\n");
|
const lines = code.innerText.split("\n");
|
||||||
|
const heredoc = RegExp(/<<\s*\\?EOF/);
|
||||||
let cmd = "";
|
let cmd = "";
|
||||||
let escape = false;
|
let escape = false;
|
||||||
let escapeUntilEOF = false;
|
let escapeUntilEOF = false;
|
||||||
let tmp = "";
|
let tmp = "";
|
||||||
|
|
||||||
for (let j = 0; j < lines.length; j++) {
|
for (let j = 0; j < lines.length; j++) {
|
||||||
const line = lines[j];
|
const line = lines[j];
|
||||||
|
|
||||||
|
|
@ -225,14 +227,14 @@ function handleCodeBlocks() {
|
||||||
|
|
||||||
tmp = line.slice(2);
|
tmp = line.slice(2);
|
||||||
|
|
||||||
if (line.includes("<<EOF")) {
|
if (heredoc.test(line)) {
|
||||||
escapeUntilEOF = true;
|
escapeUntilEOF = true;
|
||||||
}
|
}
|
||||||
} else if (escape) {
|
} else if (escape) {
|
||||||
// continuation
|
// continuation
|
||||||
tmp += "\n" + line;
|
tmp += "\n" + line;
|
||||||
|
|
||||||
if (line.includes("<<EOF")) {
|
if (heredoc.test(line)) {
|
||||||
escapeUntilEOF = true;
|
escapeUntilEOF = true;
|
||||||
}
|
}
|
||||||
} else if (escapeUntilEOF) {
|
} else if (escapeUntilEOF) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue