~aprates/gempress

10a61f11f4f4e4c423d9eb01974cd2bb93ea6699 — Antonio Prates 1 year, 1 month ago 3dcdbc9
Set extra markup conversions via config
5 files changed, 43 insertions(+), 24 deletions(-)

M README.md
M capsule-example.conf
M src/capsule-to-website.sh
M src/configure.c
M src/gmi-to-html.c
M README.md => README.md +3 -4
@@ 58,7 58,9 @@ These are the standard markup conversions currently supported by `gmi-to-html` (
- `>` blockquote
- `pre-formatted` block enclosed in triple backtick (```)

Other supported markup conversions (non-standard for Gemini):
See [Solderpunk's Gemini Specifications](https://gemini.circumlunar.space/docs/specification.gmi), section 5 for `text/gemini` media type reference.

GemPress offers 2 extra markup conversions (non-standard for Gemini), but those need to explicitly enable via configuration flag:
- `---` horizontal rule
- inline `code` enclosed in backtick (`) - see [limitations](#limitations) section



@@ 197,9 199,6 @@ Also note that, the included `atom` feed generator is a bit of a primitive tool 
```
See the [Gemini simple feed specification](gemini://gemini.circumlunar.space/docs/companion/subscription.gmi) for `/log/index.gmi` structure reference. Make sure that the URLs contain the date as the initial part of the description, as date is extracted from there. You may add normal gemini contents above, below or in-between, as any content not in that exact format will be ignored. The generator only cares about the links with description starting as YYYY-MM-DD when building the feed.

See also:
[Solderpunk's Gemini Specifications](https://gemini.circumlunar.space/docs/specification.gmi), section 5 for `text/gemini` media type reference.

## Limitations

### Inline formatting shortcomings

M capsule-example.conf => capsule-example.conf +4 -0
@@ 30,6 30,10 @@ feedDir="log"
# Language code meta, like "en-US" or "pt-BR" (optional)
#langCode="en-US"  # not set by default

# Extra markup conversions, non-standard for gemini
# horizontal rule (---) and inline code in backticks
#extraMarkup="enabled"  # not set by default

# SOURCEHUT PAGES PUBLISHING SETTINGS (OPTIONAL)

# OAuth 2.0 sr.ht personal access token

M src/capsule-to-website.sh => src/capsule-to-website.sh +9 -4
@@ 57,13 57,18 @@ cp -ux $templateDir/styles.css $website

# colect all file paths in contents and run the conversion tool
getFilePaths $website
if [[ -z $langCode ]];
conversionArgs=""
if [[ -n $extraMarkup ]];
then
    echo "Using extra markup conversion: enabled"
    conversionArgs="$conversionArgs -extraMarkup"
fi
if [[ -n $langCode ]];
then
    conversionArgs=$filePaths
else
    echo "Using language code: $langCode"
    conversionArgs="-lang:$langCode $filePaths"
    conversionArgs="$conversionArgs -lang:$langCode"
fi
conversionArgs="$conversionArgs $filePaths"
sugar src/gmi-to-html.c $conversionArgs

# clean up

M src/configure.c => src/configure.c +3 -0
@@ 78,6 78,9 @@ void configure(string path, string date) {
      "#maxAtomEntries=\"\"  # defaults to \"15\"\n\n"
      "# Language code meta, like \"en-US\" or \"pt-BR\" (optional)\n"
      "#langCode=\"en-US\"  # not set by default\n\n"
      "# Extra markup conversions, non-standard for gemini\n"
      "# horizontal rule (---) and inline code in backticks\n"
      "#extraMarkup=\"enabled\"  # not set by default\n\n"
      "# SOURCEHUT PAGES PUBLISHING SETTINGS (OPTIONAL)\n\n";

  string _srhtToken = "# OAuth 2.0 sr.ht personal access token\nsrhtToken=\"";

M src/gmi-to-html.c => src/gmi-to-html.c +24 -16
@@ 11,6 11,7 @@ bool preformattedMode;
bool itemsMode;
number linkCount;
string htmlTag = "<html>\n";
bool extraMarkup = false;

// html escape code helpers
string escapeQ(string text) { return replaceWord(text, "\"", "&quot;"); }


@@ 116,22 117,24 @@ string lineToHTML(string line) {
    return join3s("<h1>", &line[2], "</h1>");
  }

  // <horizontal rule>
  if (areSame(line, "---"))
    return "<hr />";

  // <inline code>
  number length;
  number ticksCount =
      countWord(line, "`"); // futile attempt to prevent bleeding
  if (ticksCount > 1 && ticksCount % 2 == 0) {  // simple check, no guarantees
    line = replaceWord(line, " `", " <code>");  // start inline code
    line = replaceWord(line, "` ", "</code> "); // end inline code
    if (startsWith(line, "`"))                  // if first thin in the line
      line = join2s("<code>", &line[1]);        // begin with inline code
    length = strlen(line);
    if (length > 0 && line[length - 1] == '`')  // if last…
      line = replaceWord(line, "`", "</code>"); // end inline code
  if (extraMarkup) {
    // <horizontal rule>
    if (areSame(line, "---"))
      return "<hr />";

    // <inline code>
    number length;
    number ticksCount =
        countWord(line, "`"); // futile attempt to prevent bleeding
    if (ticksCount > 1 && ticksCount % 2 == 0) {  // simple check is even
      line = replaceWord(line, " `", " <code>");  // start inline code
      line = replaceWord(line, "` ", "</code> "); // end inline code
      if (startsWith(line, "`"))                  // if first thin in the line
        line = join2s("<code>", &line[1]);        // begin with inline code
      length = strlen(line);
      if (length > 0 && line[length - 1] == '`')  // if last…
        line = replaceWord(line, "`", "</code>"); // end inline code
    }
  }

  // <list items> (accepts inline code)


@@ 146,10 149,15 @@ string lineToHTML(string line) {

// try to get the file from path and generate the corresponding html in place
void convert(string path) {
  path = replaceWord(path, " ", ""); // trim extra spaces from args
  if (startsWith(path, "-lang:")) {
    htmlTag = join3s("<html lang=\"", &path[6], "\">\n"); // set langCode
    return;
  }
  if (startsWith(path, "-extraMarkup")) {
    extraMarkup = true; // set extraMarkup
    return;
  }
  if (countWord(path, ".gmi")) {  // ultra-simple path validadion
    string text = readFile(path); // read and hope content is text/gemini :D
    if (text) {                   // safe-gard / read failure