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

parser: add markdown support #3230

Merged
merged 35 commits into from Dec 7, 2023
Merged

Conversation

landam
Copy link
Member

@landam landam commented Nov 9, 2023

This PR:

  • adds a new option --md-description to produce module usage in Markdown
  • updates RestructuredText to be synced with HTML interface description
  • uses common codebase for Markdown and RestructuredText

Example:

v.buffer --md-description

Comparision of HTML (right) and Markdown (left):

Screenshot from 2023-11-09 11-51-31

Tasks

  • solve all errors reported by markdownlint

@landam landam marked this pull request as draft November 9, 2023 11:00
@landam landam self-assigned this Nov 9, 2023
@landam landam added the enhancement New feature or request label Nov 9, 2023
@landam landam added this to the 8.4.0 milestone Nov 9, 2023
lib/gis/parser_rest_md.c Outdated Show resolved Hide resolved
@neteler
Copy link
Member

neteler commented Nov 9, 2023

A small example here would be nice:

<h2>reStructuredText</h2>

Like this:

<h2>Markdown</h2>

The flag <b>--md-description</b> added to a GRASS command
generates module interface description in Markdown, a lightweight
markup language. Example:

<div class="code"><pre>
v.in.db --md-description
</pre></div>

landam and others added 3 commits November 9, 2023 13:20
@landam
Copy link
Member Author

landam commented Nov 9, 2023

Python script to validate generated Markdown files:

import subprocess
import grass.script as gs

# https://github.com/markdownlint/markdownlint
# sudo apt install ruby-mdl

for cmd in gs.get_commands()[0]:
    out_fn = "/tmp/" + cmd + ".md"
    fd = open(out_fn, "w")
    print([cmd, "--md-description"])
    p = subprocess.Popen([cmd, "--md-description"], stdout=fd)
    p.wait()
    fd.close()
    p = subprocess.Popen(["mdl", out_fn])
    p.wait()

@wenzeslaus
Copy link
Member

Please, add the validation script to utils and run that in CI for couple tool in the additional checks workflow. This will ensure that both this PR is okay and any subsequent tweaks don't break it.

@neteler
Copy link
Member

neteler commented Nov 20, 2023

There is currently a compile error:

parser_rest_md.c: In function ‘usage_rest_md’:
parser_rest_md.c:267:29: error: format not a string literal and no format arguments [-Werror=format-security]
  267 |             fprintf(stdout, image_spec_rest);
      |                             ^~~~~~~~~~~~~~~
cc1: all warnings being treated as errors

@landam landam added manual Documentation related issues C Related code is in C labels Nov 27, 2023
@landam
Copy link
Member Author

landam commented Dec 5, 2023

Please, add the validation script to utils and run that in CI for couple tool in the additional checks workflow. This will ensure that both this PR is okay and any subsequent tweaks don't break it.

In this stage I would say that there is no need for to run validation script in CI. CI validation will be probably performed when we will modify system for generating manuals to use markdown. This PR is just about adding --md-description option to the parser.

@landam landam marked this pull request as ready for review December 5, 2023 11:59
@landam
Copy link
Member Author

landam commented Dec 5, 2023

The PR is ready for review. It adds a new option to the parser: --md-description. Usage:

v.to.db --md-description

In utils there is a script which checks whether generated markdown is valid. Usage:

Check single module:

python3 utils/md_isvalid.py -m v.to.db

Check all modules:

python3 utils/md_isvalid.py
...
--------------------------------------------------------------------------------
d.background
...
ximgview
--------------------------------------------------------------------------------
Modules processed 538 (0 failed)
--------------------------------------------------------------------------------

Currently all modules pass this test. This script can be integrated later into CI when the system for generating manual pages will be changed to use markdown (for this task a separated PR will be created).

Some validation rules are disabled (see utils/mdl_style.rb. Namely:

  • MD013 (Line length) - some lines produced by GRASS parser can be longer that 80 characters (eg. module/option/flag description/label)
  • MD034 (Bare URL used) - some lines produced by GRASS parser may contain URL, eg. g.extenstion
  • MD037 (Spaces inside emphasis markers) - some lines produced by GRASS parser may contain multiple * characters, eg. v.to.db: s = perimeter / (2 \* sqrt(PI \* area)). It doesn't help to escape *, the rule disabled

Parser was also improved for two GRASS modules:

  • r.mapcalc: use descriptions
  • v.to.db: remove extra spaces in descriptions

@landam landam requested a review from neteler December 5, 2023 12:13
lib/gis/parser_rest_md.c Outdated Show resolved Hide resolved
@landam landam requested a review from neteler December 6, 2023 15:05
Copy link
Member

@neteler neteler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work, tested with EN,DE, JA locales. Thanks!

@landam landam merged commit bcc7300 into OSGeo:main Dec 7, 2023
19 checks passed
@landam landam deleted the parser_md_description branch December 7, 2023 12:14
HuidaeCho pushed a commit to HuidaeCho/grass that referenced this pull request Jan 9, 2024
* add markdown parser description
* improve also rest parser description
* add script for markdown validation
* fix option descriptions for r.mapcalc and v.to.db

---
Co-authored-by: Markus Neteler <neteler@osgeo.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C Related code is in C enhancement New feature or request manual Documentation related issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants