Skip to content

Commit

Permalink
feat: support comfort spaces in code block meta
Browse files Browse the repository at this point in the history
  • Loading branch information
lihbr committed Dec 2, 2024
1 parent c78b38c commit 47760bd
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion data/notes/Keep Kalm, Rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ I have to admit, I was quite excited getting to that part when I started [[notes
So when do you panic in Rust? Well, just like in real life, you do when something happens and you cannot do anything about it.

Put more precisely, panicking is what you do when you encounter an unrecoverable error in Rust. As it's a thread-based mechanism, I assume it kills it in some way(?) while other threads can carry around their work, handling the panicked thread if needed.
```rust[src/main.rs]
```rust [src/main.rs]
fn main() {
if (something_bad) {
panic!();
Expand Down
4 changes: 2 additions & 2 deletions data/notes/Let's Get Coding With Rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Indeed, learning how to write it only gets you so far, at one point you also nee
This starts with code organization.

Contrary to JavaScript, Rust doesn't have an `import`/`export` system so to say because you don't import files. Instead Rust has "modules", which reminds me vaguely of PHP namespaces (for which I have a *vague* and *distant* memory of) and C includes.
```rust[src/greetings/mod.rs]
```rust [src/greetings/mod.rs]
// `greetings` module root, `mod.rs` is recognized as such

// `hello` is a public function of the `greetings` module
Expand All @@ -24,7 +24,7 @@ pub fn hello() {
```

You cannot *import* modules, instead you have to *reference* them, which you can if they are exposed to the file you're working on.
```rust[src/main.rs]
```rust [src/main.rs]
mod greetings; // reference of the `greetings` module

fn main() {
Expand Down
6 changes: 3 additions & 3 deletions data/notes/Rust Workspaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ I'm not sure yet if this comes as a result of great design and thoughtful archit
Anyway. Today I've learned about Rust built-in workspace support. Similarly to [npm's workspaces](https://docs.npmjs.com/cli/v7/using-npm/workspaces), they allow you to develop multiple packages within the same codebase, i.e. developing within a monorepo.

To leverage them, we just need to create a directory featuring a root `Cargo.toml` declaring our workspace.
```toml[Cargo.toml]
```toml [Cargo.toml]
[workspace]
members = [
"src",
"examples/hello-world"
"src",
"examples/hello-world"
]
```

Expand Down
4 changes: 2 additions & 2 deletions src/akte/lib/highlightCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ function parseLineHighlightsString(raw: string): number[][] {
export function parseMarkdownCodeBlock(markdownCodeBlock: string): ParseMarkdownCodeBlockReturnType {
const maybeMatch = markdownCodeBlock.match(
/**
* @see https://regex101.com/r/gzGiA5/1
* @see https://regex101.com/r/gzGiA5/3
*/
/^\s*\/(?<language>[\w-]+)?(?:\[(?<filename>[/\w\s.~-]*)\])?(?:\{(?<lineHighlightsString>[\s\d,-]*)\})?\/(?<code>[\s\S]*)/,
/^\s*\/(?<language>[\w-]+)?\s?(?:\[(?<filename>[/\w\s.~-]*)\])?(?:\{(?<lineHighlightsString>[\s\d,-]*)\})?\s?\/(?<code>[\s\S]*)/,
)

if (!maybeMatch || !maybeMatch.groups) {
Expand Down
2 changes: 1 addition & 1 deletion src/akte/lib/markdownToHTML.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const remarkHighlightCode: Plugin<[], MDRoot> = () => {
parent: MDParent,
): Promise<void> => {
const value = await highlightCode(
parseMarkdownCodeBlock(`/${node.lang}/\n${node.value}`),
parseMarkdownCodeBlock(`/${node.lang} ${node.meta || ""}/\n${node.value}`),
)

parent.children.splice(index, 1, { type: "html", value })
Expand Down

0 comments on commit 47760bd

Please sign in to comment.