Documented Style Sheets Parser
Перейти к файлу
semantic-release-bot 2f51e06a5a chore(release): 1.0.0 [skip ci]
# 1.0.0 (2021-03-01)

### Bug Fixes

* **parsing:** allow usage of '@' in blocks ([827ca61](827ca613f2))

### Features

* initial release from fork ([094ad94](094ad94fa7))
* **aliases:** add markup alias for example parser ([8096a53](8096a533a9))
* **aliases:** add return alias for returns parser ([2f9b1dc](2f9b1dc1ef))
* **comments:** add support for JavaDoc blocks parsing ([3d13d87](3d13d87d61))
* **parse:** add next line key and type to the output object ([c90f944](c90f9446d4))
* **parsers:** add param and return parsers for JSDoc like data ([b46e7f3](b46e7f3abb))
* **parsers:** add several parsers ([3d5dec0](3d5dec011b))
* **parsers:** allow multi-line description comments ([e609609](e609609420))
* **parsers:** allow usage of multiple example annotations ([50de3f5](50de3f5094))
* **parsers:** extract multiline parser logic from markup ([64b991e](64b991e3bf))
* **parsers:** parse example type ([20d2478](20d2478e7b))
* **parsers:** use latest JSDoc syntax for param and returs annotations ([36203e3](36203e3fef))
* **parsing:** allow parsing description without annotation ([99e711f](99e711f1a3))
* **parsing:** use triple slash single line comments ([081d1fc](081d1fc62b))
2021-03-01 14:02:19 +00:00
.github/workflows feat: initial release from fork 2021-03-01 15:59:52 +02:00
.vscode chore: add vscode launch.json for easier debugging 2021-02-11 15:05:29 +02:00
playground chore: add vscode launch.json for easier debugging 2021-02-11 15:05:29 +02:00
test feat(aliases): add markup alias for example parser 2021-02-11 14:32:49 +02:00
.commitlintrc.json chore: add commitlint and husky 2021-02-03 18:13:30 +02:00
.editorconfig feat: initial release from fork 2021-03-01 15:59:52 +02:00
.eslintignore feat: initial release from fork 2021-03-01 15:59:52 +02:00
.eslintrc chore: fix eslint errors 2021-02-03 13:13:23 +02:00
.gitignore feat: initial release from fork 2021-03-01 15:59:52 +02:00
CHANGELOG.md chore(release): 1.0.0 [skip ci] 2021-03-01 14:02:19 +00:00
LICENSE.md feat: initial release from fork 2021-03-01 15:59:52 +02:00
README.md feat: initial release from fork 2021-03-01 15:59:52 +02:00
dss.js feat(aliases): add markup alias for example parser 2021-02-11 14:32:49 +02:00
package-lock.json chore(release): 1.0.0 [skip ci] 2021-03-01 14:02:19 +00:00
package.json chore(release): 1.0.0 [skip ci] 2021-03-01 14:02:19 +00:00
release.config.js feat: initial release from fork 2021-03-01 15:59:52 +02:00

README.md

DSS

This is a fork of DSS.

DSS, Documented Style Sheets, is a comment styleguide and parser for CSS, LESS, SASS and SCSS code.

Generating Documentation

In most cases, you will want to include the DSS parser in a build step that will generate documentation files automatically.

Parser Example

Example Comment Block

/**
 * @name Button
 * @description Your standard form button.
 *
 * @state :hover - Highlights when hovering.
 * @state :disabled - Dims the button when disabled.
 * @state .primary - Indicates button is the primary action.
 * @state .smaller - A smaller button.
 *
 * @example
 * <span>
 *     <button>This is a button</button>
 * </span>
 *
 * @deprecated 123.321
 * @deprecatedDescription This is deprecated.
 *
 * @group Buttons
 * @type Color
 * @subtype Text-Color
 * @key $button-bg
 *
 * @param {string} par1 - ParmOne description.
 * @param {function} par2 - ParamTwo description.
 * @returns {number} - Return description.
 */

or

/// @name Button
/// @description Your standard form button.
///
/// @state :hover - Highlights when hovering.
/// @state :disabled - Dims the button when disabled.
/// @state .primary - Indicates button is the primary action.
/// @state .smaller - A smaller button.
///
/// @example
/// <span>
///     <button>This is a button</button>
/// </span>
///
/// @deprecated 123.321
/// @deprecatedDescription This is deprecated.
///
/// @group Buttons
/// @type Color
/// @subtype Text-Color
/// @key $button-bg
///
/// @param {string} par1 - ParmOne description.
/// @param {function} par2 - ParamTwo description.
/// @returns {number} - Return description.
///

Basic Usage

// Require/read a file
const fs = require('fs');
const dss = require('dss');
const file = fs.readFileSync('styles.scss');

// Run DSS Parser
dss.parse(file, {}, (parsed) => {
    console.log(parsed.blocks);
});

Example Generated Object

[{
    "name": "Button",
    "description": "Your standard form button.",
    "state": [
        {
            "name": ":hover",
            "escaped": "pseudo-class-hover",
            "description": "Highlights when hovering."
        },
        {
            "name": ":disabled",
            "escaped": "pseudo-class-disabled",
            "description": "Dims the button when disabled."
        },
        {
            "name": ".primary",
            "escaped": "primary",
            "description": "Indicates button is the primary action."
        },
        {
            "name": ".smaller",
            "escaped": "smaller",
            "description": "A smaller button."
        }
    ],
    "example": {
        "example": " <span>\n     <button>This is a button</button>\n </span>",
        "escaped": " &lt;span&gt;\n     &lt;button&gt;This is a button&lt;/button&gt;\n &lt;/span&gt;"
    },
    "deprecated": "123.321",
    "deprecatedDescription": "This is deprecated.",
    "group": "buttons",
    "type": "color",
    "subtype": "text-color",
    "key": "$button-bg",
    "param": [
        {
            "type": "{string}",
            "name": "par1",
            "description": "ParmOne description."
        },
        {
            "type": "{function}",
            "name": "par2",
            "description": "ParmTwo description."
        }
    ],
    "returns": {
        "type": "{number}",
        "name": null,
        "description": "Return description."
    }
}]

Parsers Specifics

  1. Only the description and example parsers allow usage of multi-line comments.
  2. If a comment block starts without an annotation, the parser sets this text as description. However, if a description annotation is available, the parser overrides the non-annotation one.
  3. If more than one example is provided, the parser returns an array of examples.
  4. The state and param parsers are returning an array of all the relevant annotations.
  5. If not defined, the parser tries to assume the type and key values based on the next line.
  6. The group, type, and subtype parsers convert the string annotation to lowercase letters.

Parser Aliases

The parser aliases set their value in the key of the main parser in the output JSON.

DSS, by default, includes the following alias - parser pairs:

  1. return - returns
  2. markup - example

Modifying Parsers

DSS, by default, includes the name, description, state, example, deprecated, deprecatedDescription, group, type, subtype, key, param, and returns parsers of a comment block. You can add to or override these default parsers using the following:

// Matches @link
dss.parser('link', (i, line, block, file) => {
    // Replace link with HTML wrapped version
    const exp = /(b(https?|ftp|file)://[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|])/ig;

    return line.replace(exp, "<a href='$1'>$1</a>");
});
// Matches @version
dss.parser('version', (i, line, block, file) => {
    return line;
});