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 headings, and group link reference definitions #620

Merged
merged 26 commits into from
Jul 1, 2022

Commits on Jun 19, 2022

  1. generate: demote level of non-first headers

    To-do: update the integration tests accordingly.
    
    Closes: 328
    ee7 committed Jun 19, 2022
    Configuration menu
    Copy the full SHA
    a098a9c View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    8e4bc8a View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    b62775e View commit details
    Browse the repository at this point in the history
  4. generate: don't alter # line inside fenced code block

    Previously, `configlet generate` assumed that every line beginning
    with a '#' character inside a concept `introduction.md` is a header.
    For our purposes, the most common exception to that idea is probably
    a comment inside a fenced code block. With this commit, we no longer
    add a '#' to such a line.
    
    The markdown handling here is rudimentary, but it may be good enough to
    avoid a full markdown parser for `configlet generate`.
    
    But this doesn't support other blocks, like HTML blocks.
    ee7 committed Jun 19, 2022
    Configuration menu
    Copy the full SHA
    5284615 View commit details
    Browse the repository at this point in the history
  5. generate: add starting level-2 heading with concept's name

    Also update the tests to assert that `configlet generate` makes no
    changes to the current state of the elixir track repo.
    
    In a later PR we'll update those tests to assert the same for
    `configlet generate -uy`.
    ee7 committed Jun 19, 2022
    Configuration menu
    Copy the full SHA
    cb47886 View commit details
    Browse the repository at this point in the history

Commits on Jun 22, 2022

  1. generate: simplify

    This is arguable. But I think this way is more readable overall by the
    time we add handling of HTML comment blocks.
    ee7 committed Jun 22, 2022
    Configuration menu
    Copy the full SHA
    2f65060 View commit details
    Browse the repository at this point in the history
  2. generate: refactor via continuesWith

    More readable, and easier to extend to support HTML comment blocks, but
    probably marginally slower.
    ee7 committed Jun 22, 2022
    Configuration menu
    Copy the full SHA
    118fd27 View commit details
    Browse the repository at this point in the history
  3. generate: support HTML comment block

    This is only one of many possible HTML blocks [1], but probably the most
    important one.
    
    [1] https://spec.commonmark.org/0.30/#html-blocks
    ee7 committed Jun 22, 2022
    Configuration menu
    Copy the full SHA
    da1d695 View commit details
    Browse the repository at this point in the history
  4. generate: don't insert h2 when under h2; demote dynamically

    Insert a h2 using the concept's name in the track `config.json`, and
    demote the headers in the `introduction.md` for the `foo` concept by 1:
    
        # Introduction
    
        %{concept:foo}
    
    Don't insert a h2, and demote by 1:
    
        # Introduction
    
        ## Foo
    
        %{concept:foo}
    
    Don't insert a h2, and demote by 2:
    
        # Introduction
    
        ## Some header
    
        Blah blah.
    
        ### Foo
    
        %{concept:foo}
    ee7 committed Jun 22, 2022
    Configuration menu
    Copy the full SHA
    3a514c2 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    d7cea65 View commit details
    Browse the repository at this point in the history

Commits on Jun 24, 2022

  1. Configuration menu
    Copy the full SHA
    ff23522 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    dc291af View commit details
    Browse the repository at this point in the history
  3. generate: put all reference links at the bottom

    Consider this `.md.tpl` file:
    
        # Introduction
    
        ## Foo
    
        %{concept:foo}
    
        ## Bar
    
        %{concept:bar}
    
    Before this commit, when more than one placeholder had a reference link,
    `configlet generate` would produce something like
    
        # Introduction
    
        ## Foo
    
        Here is a line with a link [Foo][foo].
    
        [foo]: http://www.example.com
    
        ## Bar
    
        Here is another line with a link [Bar][bar].
    
        [bar]: http://www.example.com
    
    With this commit, we place the reference links at the bottom, ordering
    by first usage, and deduplicating them:
    
        # Introduction
    
        ## Foo
    
        Here is a line with a link [Foo][foo].
    
        ## Bar
    
        Here is another line with a link [Bar][bar].
    
        [foo]: http://www.example.com
        [bar]: http://www.example.com
    
    But it's tricky to do this robustly without using a proper markdown
    parser.
    
    From the CommonMark Spec [1], the rules for reference links have some
    complexity:
    
        A link reference definition consists of a link label, optionally
        preceded by up to three spaces of indentation, followed by a colon (:),
        optional spaces or tabs (including up to one line ending),
        a link destination, optional spaces or tabs (including up to one line
        ending), and an optional link title, which if it is present must be
        separated from the link destination by spaces or tabs. No further
        character may occur.
    
        ---
    
        A link label begins with a left bracket ([) and ends with the first
        right bracket (]) that is not backslash-escaped. Between these
        brackets there must be at least one character that is not a space,
        tab, or line ending. Unescaped square bracket characters are not
        allowed inside the opening and closing square brackets of link
        labels. A link label can have at most 999 characters inside the
        square brackets.
    
    [1] https://spec.commonmark.org/0.30/#link-reference-definitions
    ee7 committed Jun 24, 2022
    Configuration menu
    Copy the full SHA
    42a8d14 View commit details
    Browse the repository at this point in the history

Commits on Jun 28, 2022

  1. generate: rename getSlugLookup proc

    Clarify the kind of slug. In the future we could even consider:
    
        type
          ConceptSlug* = distinct string
          ExerciseSlug* = distinct string
    ee7 committed Jun 28, 2022
    Configuration menu
    Copy the full SHA
    d1a1ab1 View commit details
    Browse the repository at this point in the history
  2. generate: rename header to heading

    The CommonMark spec [1] calls them headings, not headers.
    
    [1] https://spec.commonmark.org/0.30/
    ee7 committed Jun 28, 2022
    Configuration menu
    Copy the full SHA
    394221c View commit details
    Browse the repository at this point in the history
  3. generate: move writeError proc down

    Make declaration order match usage order.
    ee7 committed Jun 28, 2022
    Configuration menu
    Copy the full SHA
    3b0afc2 View commit details
    Browse the repository at this point in the history
  4. generate: add doc comment

    ee7 committed Jun 28, 2022
    Configuration menu
    Copy the full SHA
    0d88452 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    94878f0 View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    42b1460 View commit details
    Browse the repository at this point in the history
  7. generate: rename title to h2

    ee7 committed Jun 28, 2022
    Configuration menu
    Copy the full SHA
    5d333b8 View commit details
    Browse the repository at this point in the history
  8. generate: simplify demotion

    ee7 committed Jun 28, 2022
    Configuration menu
    Copy the full SHA
    09f4fca View commit details
    Browse the repository at this point in the history
  9. generate: avoid backticks

    The backticks look a bit strange, even if you know that `concept` is a
    keyword. Sidestep the issue. We named it `con` elsewhere:
    
        $ git grep --heading --break 'for .* in concepts:'
        src/info/info.nim
        32:      for con in concepts:
    
        src/lint/track_config.nim
        303:  for con in concepts:
    ee7 committed Jun 28, 2022
    Configuration menu
    Copy the full SHA
    c244d1a View commit details
    Browse the repository at this point in the history
  10. generate: use distinct Slug

    ee7 committed Jun 28, 2022
    Configuration menu
    Copy the full SHA
    1ecc512 View commit details
    Browse the repository at this point in the history
  11. Configuration menu
    Copy the full SHA
    607f369 View commit details
    Browse the repository at this point in the history
  12. generate: refer to "link reference definitions"

    That's what the CommonMark Spec [1] calls them.
    
    [1] https://spec.commonmark.org/0.30/#link-reference-definitions
    ee7 committed Jun 28, 2022
    Configuration menu
    Copy the full SHA
    4ee45ef View commit details
    Browse the repository at this point in the history

Commits on Jun 30, 2022

  1. Configuration menu
    Copy the full SHA
    7727f73 View commit details
    Browse the repository at this point in the history