mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2026-04-11 19:28:30 +00:00
"Building a Desktop LLM App with cpp-httplib" (#2403)
This commit is contained in:
18
docs-util/llm-app/extract_code.sh
Normal file
18
docs-util/llm-app/extract_code.sh
Normal file
@@ -0,0 +1,18 @@
|
||||
# Extract code block from a <details> section identified by data-file attribute.
|
||||
# Usage: extract_code <file> <data-file>
|
||||
# Example: extract_code ch01.md "main.cpp"
|
||||
extract_code() {
|
||||
local file="$1" name="$2"
|
||||
local output
|
||||
output=$(awk -v name="$name" '
|
||||
$0 ~ "data-file=\"" name "\"" { found=1; next }
|
||||
found && /^```/ && !inside { inside=1; next }
|
||||
inside && /^```/ { exit }
|
||||
inside { print }
|
||||
' "$file")
|
||||
if [ -z "$output" ]; then
|
||||
echo "ERROR: extract_code: no match for data-file=\"$name\" in $file" >&2
|
||||
return 1
|
||||
fi
|
||||
printf '%s\n' "$output"
|
||||
}
|
||||
Reference in New Issue
Block a user