Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 74 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
## Install

```sh
go install github.com/croaky/mdembed
go install github.com/croaky/mdembed@latest
```

For that to work, Go must be installed and
Expand All @@ -26,27 +26,38 @@ In `input1.md`:
Embed a whole file:

```embed
f1.rb
dir1/f1.rb
```

Embed multiple whole files:

```embed
f1.rb
f2.go
dir1/f1.rb
dir1/f2.go
```

Embed specific lines in a file:

```embed
f3.js log
dir1/subdir1/f3.js log
```

Embed multiple blocks within the same file:
Embed multiple whole files and multiple blocks within files:

```embed
f4.html h1
f4.html ul
dir1/f1.rb
dir1/f2.go log
dir2/f4.css h1
dir2/subdir2/f5.html h1
dir2/subdir2/f5.html ul
f6.sql users
```

Embed files using globs and blocks:

```embed
**/*.rb
**/*.js log
```

Embed Markdown files and their embeds recursively:
Expand All @@ -56,13 +67,13 @@ input2.md
```
````

In `f1.rb`:
In `dir1/f1.rb`:

```rb
puts "hi"
```

In `f2.go`:
In `dir1/f2.go`:

```go
package main
Expand All @@ -74,7 +85,7 @@ func main() {
}
```

In `f3.js`:
In `dir1/subdir1/f3.js`:

```js
console.log("Not embedded");
Expand All @@ -86,7 +97,7 @@ console.log("hi");
console.log("Not embedded");
```

In `f4.html`:
In `dir2/subdir2/f5.html`:

```html
<!doctype html>
Expand Down Expand Up @@ -117,7 +128,7 @@ In `input2.md`:
Embed from within an embedded Markdown file:

```embed
f1.rb
dir1/f1.rb
```
````

Expand All @@ -135,58 +146,97 @@ The output will be:
Embed a whole file:

```rb
# f1.rb
# dir1/f1.rb
puts "hi"
```

Embed multiple whole files:

```rb
# f1.rb
# dir1/f1.rb
puts "hi"
```

```go
// f2.go
// dir1/f2.go
package main

import "fmt"

func main() {
fmt.Println("hi")
// emdo log
fmt.Println("hi")
// emdone log
}
```

Embed specific lines in a file:

```js
// f3.js
// dir1/subdir1/f3.js
console.log("hi");
```

Embed multiple blocks within the same file:
Embed multiple whole files and multiple blocks within files:

```rb
# dir1/f1.rb
puts "hi"
```

```go
// dir1/f2.go
fmt.Println("hi")
```

```css
/* dir2/f4.css */
h1 {
color: blue;
}
```

```html
<!-- f4.html -->
<!-- dir2/subdir2/f5.html -->
<h1>h1</h1>
```

```html
<!-- f4.html -->
<!-- dir2/subdir2/f5.html -->
<ul>
<li>1</li>
<li>2</li>
</ul>
```

```sql
-- f6.sql
SELECT
*
FROM
users;
```

Embed files using globs and blocks:

```rb
# dir1/f1.rb
puts "hi"
```

```js
// dir1/subdir1/f3.js
console.log("hi");
```

Embed Markdown files and their embeds recursively:

## Input2

Embed from within an embedded Markdown file:

```rb
# f1.rb
# dir1/f1.rb
puts "hi"
```
````
Expand All @@ -197,6 +247,8 @@ puts "hi"
removing surrounding whitespace.
The file extension is used as the code fence attribute.

It parses exact file paths or file glob patterns.

If `emdo` and `emdone` magic comments were used, it will only embed the code
block wrapped by the magic comments.

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
25 changes: 16 additions & 9 deletions examples/input1.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,40 @@
Embed a whole file:

```embed
f1.rb
dir1/f1.rb
```

Embed multiple whole files:

```embed
f1.rb
f2.go
dir1/f1.rb
dir1/f2.go
```

Embed specific lines in a file:

```embed
f3.js log
dir1/subdir1/f3.js log
```

Embed multiple whole files and multiple blocks within files:

```embed
f1.rb
f2.go log
f4.css h1
f5.html h1
f5.html ul
dir1/f1.rb
dir1/f2.go log
dir2/f4.css h1
dir2/subdir2/f5.html h1
dir2/subdir2/f5.html ul
f6.sql users
```

Embed files using globs and blocks:

```embed
**/*.rb
**/*.js log
```

Embed Markdown files and their embeds recursively:

```embed
Expand Down
2 changes: 1 addition & 1 deletion examples/input2.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
Embed from within an embedded Markdown file:

```embed
f1.rb
dir1/f1.rb
```
32 changes: 22 additions & 10 deletions examples/outwant.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
Embed a whole file:

```rb
# f1.rb
# dir1/f1.rb
puts "hi"
```

Embed multiple whole files:

```rb
# f1.rb
# dir1/f1.rb
puts "hi"
```

```go
// f2.go
// dir1/f2.go
package main

import "fmt"
Expand All @@ -30,36 +30,36 @@ func main() {
Embed specific lines in a file:

```js
// f3.js
// dir1/subdir1/f3.js
console.log("hi");
```

Embed multiple whole files and multiple blocks within files:

```rb
# f1.rb
# dir1/f1.rb
puts "hi"
```

```go
// f2.go
// dir1/f2.go
fmt.Println("hi")
```

```css
/* f4.css */
/* dir2/f4.css */
h1 {
color: blue;
}
```

```html
<!-- f5.html -->
<!-- dir2/subdir2/f5.html -->
<h1>h1</h1>
```

```html
<!-- f5.html -->
<!-- dir2/subdir2/f5.html -->
<ul>
<li>1</li>
<li>2</li>
Expand All @@ -74,13 +74,25 @@ FROM
users;
```

Embed files using globs and blocks:

```rb
# dir1/f1.rb
puts "hi"
```

```js
// dir1/subdir1/f3.js
console.log("hi");
```

Embed Markdown files and their embeds recursively:

## Input2

Embed from within an embedded Markdown file:

```rb
# f1.rb
# dir1/f1.rb
puts "hi"
```
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module github.com/croaky/mdembed

go 1.23.5

require github.com/bmatcuk/doublestar/v4 v4.8.1
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github.com/bmatcuk/doublestar/v4 v4.8.1 h1:54Bopc5c2cAvhLRAzqOGCYHYyhcDHsFF4wWIR5wKP38=
github.com/bmatcuk/doublestar/v4 v4.8.1/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc=
Loading
Loading