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

Perfect whitespace control by -l plain-markdown #403

Open
ancms2600 opened this issue Apr 22, 2019 · 0 comments
Open

Perfect whitespace control by -l plain-markdown #403

ancms2600 opened this issue Apr 22, 2019 · 0 comments

Comments

@ancms2600
Copy link

ancms2600 commented Apr 22, 2019

I suggest everyone would benefit from this being the new plain-markdown.jst template going forward:

<%
for (const section of sections) {
    const docsText = section.docsText
        .replace(/^\s*(\/\*\*| \*\/| \* ?)/gm,'')
        .trim();

    if ('' !== docsText) { %><%=
        docsText
%>

<%
    }

    if ('' !== section.codeText.trim()) { %>
`%><%``js
<%=
        section.codeText
            .replace(/\s$/,'')
            .replace(/^(?:\s*[\r\n])+/,'')
            .replace(/(?:[\r\n]\s*)+$/,'')
%>
`%><%``

<%
    }
}
%>

Rationale:

  • omits empty comments and code lines (above and below)
  • removes extra padding above and below the code block areas, which looked accidental and annoying
  • two lines of comments next to each other will become one line (a paragraph) in markdown rendering, but two lines with a line-break between will remain two lines in markdown rendering (two paragraphs). this was not happening before.

...and my language file, for anyone else who also likes to mix use JSDocs with Docco:

{
  ".js": {"name": "javascript", "symbol": "(//|/\\*\\*|\\*/|\\*)"}
}

For an example, I like to do my JSDocs like this, so they work in Markdown, as well as IDE:

    /**
     * ### _id(t)
     * Required by all MongoDB documents,
     * and is a type of `ObjectId` from its own collection.
     *
     * type + name | description
     * ---|---
     * @param {string} t - | Name of model.
     * @returns {object} - | Instance of validation rule.
     */
    COMMON_SCHEMA._id        = t => field().objectId(t);

Currently invoking like:

# Makefile
documentation:
	yarn global add diagrams docco
	docco -t "docs/_docco_template.jst" -L "docs/_docco_languages.json" -c "/dev/null" -o "docs/" "shared/public/models/schema.js" && \
	mv docs/shared/public/models/schema.html docs/schema.md && \
	rm -rf docs/shared docs/null

Sorry, was too lazy to fork and PR this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant