Skip to content

Commit 0726e25

Browse files
committed
switch to using regexp to extract commands
1 parent 79dd78a commit 0726e25

File tree

2 files changed

+19
-25
lines changed

2 files changed

+19
-25
lines changed

preview-src/index.adoc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@ vfs
7070
<2> Wrap each streaming file in a buffer so the files can be processed by uglify.
7171
Uglify can only work with buffers, not streams.
7272

73+
Execute these commands to validate and build your site:
74+
75+
$ podman run -v $PWD:/antora:Z --rm -t antora/antora \
76+
version
77+
3.0.0
78+
$ podman run -v $PWD:/antora:Z --rm -it antora/antora \
79+
--clean \
80+
antora-playbook.yml
81+
7382
Cum dicat #putant# ne.
7483
Est in <<inline,reque>> homero principes, meis deleniti mediocrem ad has.
7584
Altera atomorum his ex, has cu elitr melius propriae.

src/js/07-copy-to-clipboard.js

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
;(function () {
22
'use strict'
3-
var commandContinuationRx = /\\\s*$/
4-
53
;[].slice.call(document.querySelectorAll('.doc pre.highlight, .doc .literalblock pre')).forEach(function (pre) {
64
var code, language, lang, copy, toast, toolbox
75
if (pre.classList.contains('highlight')) {
@@ -51,31 +49,18 @@
5149
copy.addEventListener('click', writeToClipboard.bind(copy, code))
5250
})
5351

52+
function extractCommands (text) {
53+
var cmdRx = /^\$ (\S[^\\\n]*(\\\n(?!\$ )[^\\\n]*)*)(?=\n|$)/gm
54+
var cleanupRx = /( )? *\\\n */g
55+
var cmds = []
56+
var m
57+
while ((m = cmdRx.exec(text))) cmds.push(m[1].replace(cleanupRx, '$1'))
58+
return cmds.join(' && ')
59+
}
60+
5461
function writeToClipboard (code) {
5562
var text = code.innerText
56-
if (code.dataset.lang === 'console' && text.startsWith('$ ')) {
57-
var lines = text.split('\n')
58-
var currentCommand = ''
59-
var commands = []
60-
var commandContinuationFound = false
61-
for (var i = 0; i < lines.length; i++) {
62-
var line = lines[i]
63-
if (!commandContinuationFound && !line.startsWith('$ ')) {
64-
// ignore, command output
65-
} else {
66-
if (commandContinuationFound) {
67-
currentCommand += '\n' + line
68-
} else if (line.startsWith('$ ')) {
69-
currentCommand = line.slice(2)
70-
}
71-
commandContinuationFound = line.match(commandContinuationRx)
72-
if (!commandContinuationFound) {
73-
commands.push(currentCommand)
74-
}
75-
}
76-
}
77-
text = commands.join('; ')
78-
}
63+
if (code.dataset.lang === 'console' && text.startsWith('$ ')) text = extractCommands(text)
7964
window.navigator.clipboard.writeText(text).then(
8065
function () {
8166
this.classList.add('clicked')

0 commit comments

Comments
 (0)