Skip to content
Open
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
20 changes: 10 additions & 10 deletions EMBEDDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ Use glob-style patterns to match the start and end lines of the fragment.

## Embedding instruction format

An `<embed-code>` instruction must always be followed by a Markdown code fence
(opening and closing triple backticks).
An `<embed-code>` instruction must always be followed by a Markdown code fence
(opening and closing triple backticks).

````markdown
<embed-code file="java/lang/String.java" fragment="Constructor"></embed-code>
Expand All @@ -47,7 +47,7 @@ To define a named fragment in your source code, wrap the desired lines with
```java
public final class String
implements java.io.Serializable, Comparable<String>, CharSequence {

// #docfragment "Constructor"
public String() {
this.value = new char[0];
Expand Down Expand Up @@ -205,15 +205,15 @@ Supported values:

Unknown extensions are embedded unchanged.

Not all languages has difference between documentation/regular or inline/block comments.
Not all languages distinguish documentation from regular comments or inline from block comments.

The table below lists the supported languages and supported `comments` modes for them:

| Language | Extensions | Supported `comments` modes |
|------------------------|---------------------------------------------------------|--------------------------------------------------------------|
| Java, Kotlin, Groovy | `.java`, `.kt`, `.kts`, `.groovy` | `all`, `none`, `documentation`, `regular`, `inline`, `block` |
| C# | `.cs` | `all`, `none`, `documentation`, `regular`, `inline`, `block` |
| C, C++ | `.c`, `.h`, `.cc`, `.cpp`, `.cxx`,`.hh`, `.hpp`, `.hxx` | `all`, `none`, `inline`, `block` |
| C, C++ | `.c`, `.h`, `.cc`, `.cpp`, `.cxx`, `.hh`, `.hpp`, `.hxx` | `all`, `none`, `inline`, `block` |
| JavaScript, TypeScript | `.js`, `.jsx`, `.ts`, `.tsx` | `all`, `none`, `documentation`, `regular`, `inline`, `block` |
| Go | `.go` | `all`, `none`, `inline`, `block` |
| Protobuf | `.proto` | `all`, `none`, `inline`, `block` |
Expand All @@ -226,9 +226,9 @@ The table below lists the supported languages and supported `comments` modes for

### Joining several parts of code into one fragment

A named fragment may consist of one or several pieces declared in a single file.
When rendered, the pieces that belong to a single fragment are joined together.
It is possible to specify a separator between the joined pieces,
A named fragment may consist of one or several pieces declared in a single file.
When rendered, the pieces that belong to a single fragment are joined together.
It is possible to specify a separator between the joined pieces,
see [Configuration](./README.md#arguments) for the corresponding parameter.

Here is an example of how a multi-piece fragment is rendered.
Expand All @@ -245,7 +245,7 @@ public final class String
return hash;
}
// #enddocfragment "Standard Object methods"

/* Here goes irrelevant code */

// #docfragment "Standard Object methods"
Expand Down Expand Up @@ -313,7 +313,7 @@ public final class String
}
// #enddocfragment "All methods"
}
```
```

### Usage with other languages

Expand Down
23 changes: 14 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,11 @@ The available arguments are:
* `-docs-path`: (Optional) Path to the documentation root directory.
* `-config-path`: (Optional) Path to a YAML configuration file containing `code-path` and `docs-path`.
* `-doc-includes`: (Optional) Comma-separated glob patterns for documentation files to include. Defaults to `"**/*.md,**/*.html"`.
* `-doc-excludes`: (Optional) Comma-separated glob patterns for documentation files to exclude.
* `-separator`: (Optional) String used to separate joined code fragments. Defaults to `...`.

* `-info`: (Optional) Enables info-level logging when set to `true`.
* `-stacktrace`: (Optional) Prints stack traces for panics when set to `true`.

Even though the `code-path`, `docs-path`, and `config-path` arguments are optional,
Embed Code still requires the root directories for code and documentation to be set.
This can be done in one of two ways:
Expand Down Expand Up @@ -108,19 +111,19 @@ The available fields for the configuration file are:
```
* multiple named paths:
```yaml
code-path:
code-path:
- name: examples
path: path/to/code/root1
- name: production
path: path/to/code/root2
```
When a named path is specified, fragments must be referenced in the embedding instructions
When a named path is specified, fragments must be referenced in the embedding instructions
using the corresponding path name:
```md
<embed-code file="$PATH_NAME/path/to/file"></embed-code>
```
**Do not forget the dollar sign (`$`) before the path name.**

Code source names must be unique. A configuration may use either one unnamed
code source or one or more named code sources, but named and unnamed sources
cannot be mixed.
Expand All @@ -131,6 +134,8 @@ The available fields for the configuration file are:
* `doc-includes`: (Optional) Glob patterns for documentation files to include.
It may be represented as a comma-separated string list or as a YAML sequence.
* `separator`: (Optional) Separator for fragments.
* `info`: (Optional) Enables info-level logging.
* `stacktrace`: (Optional) Prints stack traces for panics.
* `embeddings`: (Optional) A list of complete embedding configurations for multiple
documentation targets. When `embeddings` is set, do not set root-level `code-path`
or `docs-path`. Define `code-path`, `docs-path`, and optional settings inside each entry.
Expand All @@ -153,19 +158,19 @@ However, you can also compile the utility manually if Go is [installed](#install

Navigate to the project root and run:
```bash
go build -trimpath main.go
go build -trimpath -o embed-code main.go
```

There may be issues when running `go build` outside of the directory containing `main.go`,
even if the path is specified correctly.

This command creates an executable named `embed-code` (or `embed-code.exe` on Windows).
This command creates an executable named `embed-code`.
For further information, please refer to the [docs](https://pkg.go.dev/cmd/go#hdr-Compile_packages_and_dependencies).

Without the `-trimpath` flag, Go includes absolute file paths in stack traces
based on the system where the binary was built.
Without the `-trimpath` flag, Go includes absolute file paths in stack traces
based on the system where the binary was built.

Run following command to build binaries for macOS, Windows and Ubuntu:
Run the following command to build binaries for macOS, Windows and Ubuntu:
```bash
mkdir -p bin && \
GOOS=darwin GOARCH=amd64 go build -trimpath -o bin/embed-code-macos main.go && chmod +x bin/embed-code-macos && \
Expand Down
10 changes: 6 additions & 4 deletions configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ import (
)

const (
// DefaultSeparator joins multiple partitions of a single fragment.
DefaultSeparator = "..."
)

// DefaultDocIncludes contains the default documentation glob patterns.
var DefaultDocIncludes = []string{"**/*.md", "**/*.html"}

// Configuration contains the settings for the plugin to work.
Expand Down Expand Up @@ -57,16 +59,16 @@ type Configuration struct {
// The default value is ["**/*.md", "**/*.html"].
DocIncludes []string

// DocExcludes is a list of patterns for filtering which we should not include for embedding
// instructions.
// DocExcludes is a list of patterns for documentation files that should not be
// processed for embedding instructions.
//
// The patterns are resolved relatively to the `documentation_root`.
//
// By the such a pattern, it can be both directories and files.
// A pattern can match both directories and files.
//
// For example, ["old-docs/**/*.md", "old-docs-v1/**/*"]
//
// Be the default, it is not set.
// By default, it is not set.
DocExcludes []string

// Separator is a string that's inserted between multiple partitions of a single fragment.
Expand Down
Loading
Loading