submark: Extract a part from CommonMark/Markdown docs

[ gpl, library, program, text ] [ Propose Tags ]

Modules

[Index] [Quick Jump]

Flags

Manual Flags

NameDescriptionDefault
static

Static link

Disabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0, 0.2.0, 0.3.0, 0.3.1
Change log CHANGELOG.md
Dependencies base (>=4.7 && <5), cmark (>=0.5.6 && <0.6.0), optparse-applicative (>=0.13.2.0 && <0.17.0.0), regex-tdfa (>=1.3.1.2 && <1.4), submark, text (>=1 && <2) [details]
License GPL-3.0-only
Copyright (c) 2017 Hong Minhee
Author Hong Minhee
Maintainer hong.minhee@gmail.com
Category Text
Home page https://github.com/dahlia/submark#readme
Bug tracker https://github.com/dahlia/submark/issues
Source repo head: git clone https://github.com/dahlia/submark
Uploaded by hongminhee at 2022-03-11T00:30:49Z
Distributions
Executables submark
Downloads 1000 total (13 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2022-03-11 [all 1 reports]

Readme for submark-0.3.0

[back to package description]

submark: Extract a part from CommonMark/Markdown docs

GitHub Actions Hackage

submark is a CLI program to extract some particular section from a given CommonMark/Markdown document. I use it for myself to extract the latest version section from the CHANGELOG.md file, and then reuse the text for the corresponding release note on GitHub releases, during automated release process which is run on CI.

Download & installation

Prebuilt binaries for the following platforms and architectures are available on GitHub releases:

  • Linux (x86_64)
  • macOS (x86_64)
  • Windows (win64)

For other platforms and architectures, you need to build it by yourself. It's written in Haskell, so you need to install Haskell Stack first. It can be built in the same way other Haskell programs are:

$ stack setup && stack install

Usage examples

The following examples use John Gruber's original Markdown introduction:

$ wget https://daringfireball.net/projects/markdown/index.text

Extracting an H3 heading Command-Line:

$ submark --h3 "Command-Line" index.text
### Command-Line

Use the `--html4tags` command-line switch to produce HTML output from a
Unix-style command line. E.g.:

    % perl Markdown.pl --html4tags foo.text

Type `perldoc Markdown.pl`, or read the POD documentation within the
Markdown.pl source code for more information.

Note that its textual style differ from the original text. Since submark internally builds an abstract syntax tree from the given input text and then render again the result tree, it doesn't maintain trivial styles (e.g., whitespaces, ATX vs. Setext headings) but only the semantics.

There are options from --h1 to --h6:

$ submark --h2 "Download" index.text
## Download

[Markdown 1.0.1](http://daringfireball.net/projects/downloads/Markdown_1.0.1.zip)
(18 KB) -- 17 Dec 2004

Options from --h1-regex to --h6-regex take a regular expression instead of an exact heading text:

$ submark --h2-regex "^(Down|Up)load$" index.text
## Download

[Markdown 1.0.1](http://daringfireball.net/projects/downloads/Markdown_1.0.1.zip)
(18 KB) -- 17 Dec 2004

The leading heading can be omitted:

$ submark --h2 "Download" --omit-heading index.text
[Markdown 1.0.1](http://daringfireball.net/projects/downloads/Markdown_1.0.1.zip)
(18 KB) -- 17 Dec 2004

Matching is case sensitive by default, but case can be ignored using the option -i/--ignore-case:

$ submark --h2 "DOWNload" index.text

$ submark --h2 "DOWNload" --ignore-case index.text
## Download

[Markdown 1.0.1](http://daringfireball.net/projects/downloads/Markdown_1.0.1.zip)
(18 KB) -- 17 Dec 2004

By Unix convention, - means pipe:

$ submark --h2 "Download" - < index.text
## Download

[Markdown 1.0.1](http://daringfireball.net/projects/downloads/Markdown_1.0.1.zip)
(18 KB) -- 17 Dec 2004

There's -o/--out-file option as well:

$ submark -o download.md --h2 "Download" index.text

Software license

This software is distributed under GPL 3.