Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generate: demote level of other headings by 1 #328

Closed
ee7 opened this issue May 12, 2021 · 0 comments · Fixed by #620
Closed

generate: demote level of other headings by 1 #328

ee7 opened this issue May 12, 2021 · 0 comments · Fixed by #620
Assignees
Labels
kind: feature User-facing enhancement priority: high More important

Comments

@ee7
Copy link
Member

ee7 commented May 12, 2021

Given an introduction.md.tpl file with the structure:

# Introduction

## Date and Time

%{concept:date-time}

configlet generate produced the Concept Exercise introduction.md file with the structure:

# Introduction

## Date and Time

Blah blah.

## A heading from the concept's `introduction.md` file

Blah blah.

It should demote` the level of an inserted heading when appropriate:

# Introduction

## Date and Time

Blah blah.

### A heading from the concept's `introduction.md` file

Blah blah.
@ee7 ee7 added the kind: feature User-facing enhancement label May 12, 2021
@ee7 ee7 added the priority: high More important label Apr 1, 2022
@ee7 ee7 changed the title generate: reduce level of other headings by 1 generate: demote level of other headings by 1 Jun 17, 2022
@ee7 ee7 self-assigned this Jun 17, 2022
@ee7 ee7 moved this to In Progress in Configlet roadmap Jun 30, 2022
@ee7 ee7 closed this as completed in #620 Jul 1, 2022
ee7 added a commit that referenced this issue Jul 1, 2022
Before this commit, the implementation of `configlet generate` was
noticeably incomplete - it could produce files with incorrect heading
levels.

Given a Concept Exercise with an `introduction.md.tpl` file like:

    # Introduction

    ## Date and Time

    %{concept:date-time}

`configlet generate` would write an `introduction.md` file, inserting
the introduction for the `date-time` Concept, but without demoting its
headings:

    # Introduction

    ## Date and Time

    Blah blah.

    ## A heading from the date-time `introduction.md` file

    Blah blah.

With this commit, configlet will demote the level of an inserted heading
when appropriate:

    # Introduction

    ## Date and Time

    Blah blah.

    ### A heading from the date-time `introduction.md` file

    Blah blah.

`configlet generate` now also writes the same when given the template
structure of:

    # Introduction

    %{concept:date-time}

That is, it adds a level-2 heading when the placeholder is not already
under a level-2 heading - we concluded that this looks better on the
website. The heading's contents are taken from the concept's `name` in
the track-level `config.json` file, so you may prefer to omit such
level-2 headings in the template file (unless you want the heading
contents to be different).

This commit also fixes configlet's handling of link reference
definitions. Consider this `introduction.md.tpl` file:

    # Introduction

    ## Foo

    %{concept:foo}

    ## Bar

    %{concept:bar}

Before this commit, when more than one placeholder had a link reference
definition, `configlet generate` would produce something like:

    # Introduction

    ## Foo

    Here is a line with a link to [Foo][foo].

    [foo]: http://www.example.com

    ## Bar

    Here is another line with a link to [Bar][bar].

    [bar]: http://www.example.org

That is, it would not combine link reference definitions at the bottom.
With this commit, it does so - ordering by first usage, and
deduplicating them:

    # Introduction

    ## Foo

    Here is a line with a link to [Foo][foo].

    ## Bar

    Here is another line with a link to [Bar][bar].

    [foo]: http://www.example.com
    [bar]: http://www.example.org

The Markdown handling in this commit is deliberately rudimentary, and
has some limitations. We're doing it this way because there is no
pure-Nim Markdown parser and renderer that does what we want. The
plan is to use a wrapper for libcmark [1], the reference implementation
of the CommonMark Spec [2].

However, cmark is not designed foremost to be a Markdown formatter - for
example, it inlines a link destination from a matching link reference
definition. But we want to generate `introduction.md` files without that
inlining, so we need patch or workaround cmark's rendering. There's some
complexity there that's best left for another commit.

[1] https://github.com/commonmark/cmark
[2] https://spec.commonmark.org/0.30

Closes: #328
Closes: #626
Repository owner moved this from In Progress to Done in Configlet roadmap Jul 1, 2022
glennj pushed a commit to glennj/exercism-configlet that referenced this issue Jul 8, 2022
…cism#620)

Before this commit, the implementation of `configlet generate` was
noticeably incomplete - it could produce files with incorrect heading
levels.

Given a Concept Exercise with an `introduction.md.tpl` file like:

    # Introduction

    ## Date and Time

    %{concept:date-time}

`configlet generate` would write an `introduction.md` file, inserting
the introduction for the `date-time` Concept, but without demoting its
headings:

    # Introduction

    ## Date and Time

    Blah blah.

    ## A heading from the date-time `introduction.md` file

    Blah blah.

With this commit, configlet will demote the level of an inserted heading
when appropriate:

    # Introduction

    ## Date and Time

    Blah blah.

    ### A heading from the date-time `introduction.md` file

    Blah blah.

`configlet generate` now also writes the same when given the template
structure of:

    # Introduction

    %{concept:date-time}

That is, it adds a level-2 heading when the placeholder is not already
under a level-2 heading - we concluded that this looks better on the
website. The heading's contents are taken from the concept's `name` in
the track-level `config.json` file, so you may prefer to omit such
level-2 headings in the template file (unless you want the heading
contents to be different).

This commit also fixes configlet's handling of link reference
definitions. Consider this `introduction.md.tpl` file:

    # Introduction

    ## Foo

    %{concept:foo}

    ## Bar

    %{concept:bar}

Before this commit, when more than one placeholder had a link reference
definition, `configlet generate` would produce something like:

    # Introduction

    ## Foo

    Here is a line with a link to [Foo][foo].

    [foo]: http://www.example.com

    ## Bar

    Here is another line with a link to [Bar][bar].

    [bar]: http://www.example.org

That is, it would not combine link reference definitions at the bottom.
With this commit, it does so - ordering by first usage, and
deduplicating them:

    # Introduction

    ## Foo

    Here is a line with a link to [Foo][foo].

    ## Bar

    Here is another line with a link to [Bar][bar].

    [foo]: http://www.example.com
    [bar]: http://www.example.org

The Markdown handling in this commit is deliberately rudimentary, and
has some limitations. We're doing it this way because there is no
pure-Nim Markdown parser and renderer that does what we want. The
plan is to use a wrapper for libcmark [1], the reference implementation
of the CommonMark Spec [2].

However, cmark is not designed foremost to be a Markdown formatter - for
example, it inlines a link destination from a matching link reference
definition. But we want to generate `introduction.md` files without that
inlining, so we need patch or workaround cmark's rendering. There's some
complexity there that's best left for another commit.

[1] https://github.com/commonmark/cmark
[2] https://spec.commonmark.org/0.30

Closes: exercism#328
Closes: exercism#626
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: feature User-facing enhancement priority: high More important
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant