-
Notifications
You must be signed in to change notification settings - Fork 362
Allow code blocks to import code from files or URLs #4236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Blargian
wants to merge
8
commits into
ClickHouse:main
Choose a base branch
from
Blargian:code_block_imports
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
cdd0176
add ability to import code block from a file
Blargian cac3230
Update config-unstructured-logs-with-processor.yaml
Blargian 4388250
Update remark-code-import.js
Blargian 620ae80
modify script plugin so that snippets update on build permanently
Blargian 1c48f18
use external file for code snippets
Blargian c0644d2
Update style guide to include new import methods and add ability to i…
Blargian 9924be0
Update code-import-plugin.js
Blargian 950c1cd
Merge branch 'ClickHouse:main' into code_block_imports
Blargian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
code_snippets/ClickStack/config-unstructured-logs-with-processor.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
receivers: | ||
filelog: | ||
include: | ||
- /opt/data/logs/access-unstructured.log | ||
start_at: beginning | ||
operators: | ||
- type: regex_parser | ||
regex: '^(?P<ip>[\d.]+)\s+-\s+-\s+\[(?P<timestamp>[^\]]+)\]\s+"(?P<method>[A-Z]+)\s+(?P<url>[^\s]+)\s+HTTP/[^\s]+"\s+(?P<status>\d+)\s+(?P<size>\d+)\s+"(?P<referrer>[^"]*)"\s+"(?P<user_agent>[^"]*)"' | ||
timestamp: | ||
parse_from: attributes.timestamp | ||
layout: '%d/%b/%Y:%H:%M:%S %z' | ||
#22/Jan/2019:03:56:14 +0330 | ||
processors: | ||
batch: | ||
timeout: 1s | ||
send_batch_size: 100 | ||
memory_limiter: | ||
check_interval: 1s | ||
limit_mib: 2048 | ||
spike_limit_mib: 256 | ||
exporters: | ||
# HTTP setup | ||
otlphttp/hdx: | ||
endpoint: 'http://localhost:4318' | ||
headers: | ||
authorization: <YOUR_INGESTION_API_KEY> | ||
compression: gzip | ||
|
||
# gRPC setup (alternative) | ||
otlp/hdx: | ||
endpoint: 'localhost:4317' | ||
headers: | ||
authorization: <YOUR_API_INGESTION_KEY> | ||
compression: gzip | ||
service: | ||
telemetry: | ||
metrics: | ||
address: 0.0.0.0:9888 # Modified as 2 collectors running on same host | ||
pipelines: | ||
logs: | ||
receivers: [filelog] | ||
processors: [batch] | ||
exporters: [otlphttp/hdx] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const { visit } = require('unist-util-visit'); | ||
|
||
function createCodeImportPlugin(options = {}) { | ||
const { baseDir = process.cwd() } = options; | ||
return function transformer(tree, file) { | ||
visit(tree, 'code', (node) => { | ||
const { lang, meta } = node; | ||
|
||
// Check if file= is in meta or lang | ||
let fileMatch = null; | ||
let filePath = null; | ||
|
||
if (meta) { | ||
fileMatch = meta.match(/file=([^\s]+)/); | ||
} | ||
if (!fileMatch && lang) { | ||
fileMatch = lang.match(/file=([^\s]+)/); | ||
if (fileMatch) { | ||
// Extract real language (everything before file=) | ||
const realLang = lang.split(/\s+file=/)[0].trim(); | ||
node.lang = realLang; | ||
} | ||
} | ||
|
||
if (!fileMatch) return; | ||
|
||
filePath = fileMatch[1]; | ||
const absolutePath = path.resolve(baseDir, filePath); | ||
|
||
try { | ||
const content = fs.readFileSync(absolutePath, 'utf8'); | ||
node.value = content; | ||
|
||
// Clean up meta if it had file= | ||
if (meta && meta.includes('file=')) { | ||
node.meta = meta.replace(/file=[^\s]+\s*/, '').trim() || null; | ||
} | ||
} catch (error) { | ||
console.warn(`Could not read file ${filePath}: ${error.message}`); | ||
} | ||
}); | ||
}; | ||
}; | ||
|
||
module.exports = createCodeImportPlugin; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11754,6 +11754,14 @@ [email protected]: | |
iconv-lite "0.4.24" | ||
unpipe "1.0.0" | ||
|
||
raw-loader@^4.0.2: | ||
version "4.0.2" | ||
resolved "https://registry.yarnpkg.com/raw-loader/-/raw-loader-4.0.2.tgz#1aac6b7d1ad1501e66efdac1522c73e59a584eb6" | ||
integrity sha512-ZnScIV3ag9A4wPX/ZayxL/jZH+euYb6FcUinPcgiQW0+UBtEv0O6Q3lGd3cqJ+GHH+rksEv3Pj99oxJ3u3VIKA== | ||
dependencies: | ||
loader-utils "^2.0.0" | ||
schema-utils "^3.0.0" | ||
|
||
[email protected], rc@^1.2.7: | ||
version "1.2.8" | ||
resolved "https://registry.yarnpkg.com/rc/-/rc-1.2.8.tgz#cd924bf5200a075b83c188cd6b9e211b7fc0d3ed" | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.