mark/README.md

255 lines
6.5 KiB
Markdown
Raw Normal View History

2015-09-20 00:34:52 +06:00
# Mark
2016-11-30 18:44:32 +07:00
Mark — tool for syncing your markdown documentation with Atlassian Confluence
pages.
2015-09-20 00:34:52 +06:00
This is very usable if you store documentation to your orthodox software in git
repository and don't want to do a handjob with updating Confluence page using
fucking tinymce wysiwyg enterprise core editor.
You can store a user credentials in the configuration file, which should be
located in ~/.config/mark with following format:
```toml
2015-09-20 00:34:52 +06:00
username = "smith"
password = "matrixishere"
base_url = "http://confluence.local"
2015-09-20 00:34:52 +06:00
```
*NOTE: Cloud Confluence also need to specify /wiki path to the base_url
parameter.*
Mark understands extended file format, which, still being valid markdown,
contains several metadata headers, which can be used to locate page inside
Confluence instance and update it accordingly.
File in extended format should follow specification
```markdown
2019-05-01 16:58:28 +03:00
<!-- Space: <space key> -->
<!-- Parent: <parent 1> -->
<!-- Parent: <parent 2> -->
<!-- Title: <title> -->
2020-06-25 00:36:08 -05:00
<!-- ExactAttachment: <local path> -->
<!-- Attachment: <local path> -->
<page contents>
```
2019-08-02 22:58:08 +03:00
There can be any number of 'Parent' headers, if mark can't find specified
parent by title, it will be created.
2019-08-02 22:58:08 +03:00
Also, optional following headers are supported:
```markdown
<!-- Layout: (article|plain) -->
```
* (default) article: content will be put in narrow column for ease of
reading;
* plain: content will fill all page;
2019-08-08 15:17:44 +03:00
Mark supports Go templates, which can be included into article by using path
2019-08-02 22:58:08 +03:00
to the template relative to current working dir, e.g.:
```markdown
<!-- Include: <path> -->
```
Templates may accept configuration data in YAML format which immediately
follows include tag:
```markdown
<!-- Include: <path>
<yaml-data> -->
```
2020-06-25 00:36:08 -05:00
Mark also supports attachments. The standard way involves declaring an
`Attachment` along with the other items in the header, then have any links
start with an `attachment://` pseudo-URL:
```markdown
<!-- Attachment: <path> -->
<beginning of page content>
An attached link is [here](attachment://<path>)
```
The standard attachment mechanism may not work in some circumstances (e.g.
keeping content as close to identical as possible between GitHub and
Confluence), so `ExactAttachment` has been introduced:
```markdown
<!-- ExactAttachment: <path> -->
<beginning of page content>
An attached link is [here](<path>)
```
2020-06-25 00:41:42 -05:00
**NOTE**: Be careful with `ExactAttachment`! If your path string is a subset of
2020-06-25 00:36:08 -05:00
another longer string or referenced in text, you may get undesired behavior.
2019-08-02 22:58:08 +03:00
Mark also supports macro definitions, which are defined as regexps which will
be replaced with specified template:
```markdown
<!-- Macro: <regexp>
Template: <path>
<yaml-data> -->
```
2019-08-08 15:17:44 +03:00
Capture groups can be defined in the macro's <regexp> which can be later
referenced in the `<yaml-data>` using `${<number>}` syntax, where `<number>` is
number of a capture group in regexp (`${0}` is used for entire regexp match),
for example:
```markdown
<!-- Macro: MYJIRA-\d+
Template: ac:jira:ticket
Ticket: ${0} -->
```
2019-08-02 22:58:08 +03:00
By default, mark provides several built-in templates and macros:
* template `ac:status` to include badge-like text, which accepts following
parameters:
- Title: text to display in the badge
- Color: color to use as background/border for badge
- Grey
- Red
- Yellow
- Green
- Blue
- Subtle: specify to fill badge with background or not
- true
- false
2019-08-06 18:07:40 +03:00
* template `ac:jira:ticket` to include JIRA ticket link. Parameters:
- Ticket: Jira ticket number like BUGS-123.
2019-08-02 22:58:08 +03:00
See: https://confluence.atlassian.com/conf59/status-macro-792499207.html
* macro `@{...}` to mention user by name specified in the braces.
## Template & Macros Usecases
### Insert Disclamer
**disclamer.md**
```markdown
**NOTE**: this document is generated, do not edit manually.
```
**article.md**
```markdown
<!-- Space: TEST -->
<!-- Title: My Article -->
<!-- Include: disclamer.md -->
This is my article.
```
### Insert Status Badge
**article.md**
```markdown
<!-- Space: TEST -->
<!-- Title: TODO List -->
<!-- Macro: :done:
Template: ac:status
Title: DONE
Color: Green -->
<!-- Macro: :todo:
Template: ac:status
Title: TODO
Color: Blue -->
* :done: Write Article
* :todo: Publish Article
```
## Insert Jira Ticket
**article.md**
```markdown
<!-- Space: TEST -->
<!-- Title: TODO List -->
<!-- Macro: MYJIRA-\d+
2019-08-06 18:07:40 +03:00
Template: ac:jira:ticket
2019-08-02 22:58:08 +03:00
Ticket: ${0} -->
See task MYJIRA-123.
```
## Usage
2015-09-20 00:34:52 +06:00
```
mark [options] [-u <username>] [-p <password>] [-k] [-l <url>] -f <file>
mark [options] [-u <username>] [-p <password>] [-k] [-n] -c <file>
2015-09-20 00:34:52 +06:00
mark -v | --version
mark -h | --help
```
2016-11-30 18:47:05 +07:00
- `-u <username>` — Use specified username for updating Confluence page.
- `-p <password>` — Use specified password for updating Confluence page.
- `-l <url>` — Edit specified Confluence page.
If -l is not specified, file should contain metadata (see above).
- `-f <file>` — Use specified markdown file for converting to html.
- `-c <file>` — Specify configuration file which should be used for reading
Confluence page URL and markdown file path.
- `-k` — Lock page editing to current user only to prevent accidental
manual edits over Confluence Web UI.
- `--dry-run` — Show resulting HTML and don't update Confluence page content.
- `--trace` — Enable trace logs.
- `-v | --version` — Show version.
- `-h | --help` — Show help screen and call 911.
# Tricks
## Confluence & Gitlab integration
Mark was created with CI in mind so you can easily integrate mark into your
pipeline, put the following code to your .gitlab-ci.yml in repository with your
markdown docs:
```yaml
stages:
- apply
Apply:
stage: apply
script:
- files=($(
git diff
$CI_COMMIT_BEFORE_SHA..$CI_COMMIT_SHA
--name-only
--diff-filter=ACMRT
| grep '.md$'
));
if [[ "${#files[@]}" == "0" ]]; then exit 0; fi;
set -e;
for file in ${files[@]}; do
echo;
echo "> Uploading ${file}";
docker run --rm -i -v=$(pwd):/docs
kovetskiy/mark:latest
-u $DOCS_WIKI_USERNAME
-p $DOCS_WIKI_PASSWORD
-b $DOCS_WIKI_BASE_URL
-f ${file};
done
```
and declare the following environment variables (secrets)
* `DOCS_WIKI_USERNAME` — Username for access to Confluence
* `DOCS_WIKI_PASSWORD` — Password for access to Confluence
* `DOCS_WIKI_BASE_URL` — Base URL of Confluence (cloud users should add /wiki at the end)