Socket
Socket
Sign inDemoInstall

select-section

Package Overview
Dependencies
2
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    select-section

Cut out sections from TxtAST.


Version published
Weekly downloads
1.1K
decreased by-27.07%
Maintainers
1
Install size
72.6 kB
Created
Weekly downloads
 

Readme

Source

select-section

Cut out sections from TxtAST or mdast.

Section?

A section is slitted by Header Node.

This rule defined section as following:

The Markdown contents

# Header1

text.

# Header2

text.

to be

------------|---- # Header 1
            | 
Section1    |     text.
            |
------------|---- # Header 2
            |
Section2    |     text.
            |
------------|---------------

Same Level header

A section is slitted by Header Node.

This rule defined section as following:

The Markdown contents

# Header1

text.

## Header2

text.

to be

--------------------------|---- # Header 1
                          | 
  Section1                |     text.
                          |
            --------------|---- ## Header 2
            -            -|
            -  Section2  -|     text.
            -            -|
--------------------------|---------------

Tree view:

└── _Section1_
    ├── # Header 1
    ├── text.
    └── _Section2_
        ├── ## Header 2
        └── text.

Install

Install with npm:

npm install select-section

Usage

Create "Section" node that compatible with TxtAST.

const createSections = require("select-section");
const parse = require("markdown-to-ast").parse;
const AST = parse(`# Header
text1
text1

# Header

text2
text2`);
const results = createSections(AST);
/*
[
    {
        "type": "Section",
        "range": [
            0,
            20
        ],
        "loc": {
            "start": {
                "line": 1,
                "column": 0
            },
            "end": {
                "line": 3,
                "column": 5
            }
        },
        "raw": "# Headertext1\ntext1",
        "children": [
            {
                "type": "Header",
                "depth": 1,
                "children": [
                    {
                        "type": "Str",
                        "value": "Header",
                        "loc": {
                            "start": {
                                "line": 1,
                                "column": 2
                            },
                            "end": {
                                "line": 1,
                                "column": 8
                            }
                        },
                        "range": [
                            2,
                            8
                        ],
                        "raw": "Header"
                    }
                ],
                "loc": {
                    "start": {
                        "line": 1,
                        "column": 0
                    },
                    "end": {
                        "line": 1,
                        "column": 8
                    }
                },
                "range": [
                    0,
                    8
                ],
                "raw": "# Header"
            },
            {
                "type": "Paragraph",
                "children": [
                    {
                        "type": "Str",
                        "value": "text1\ntext1",
                        "loc": {
                            "start": {
                                "line": 2,
                                "column": 0
                            },
                            "end": {
                                "line": 3,
                                "column": 5
                            }
                        },
                        "range": [
                            9,
                            20
                        ],
                        "raw": "text1\ntext1"
                    }
                ],
                "loc": {
                    "start": {
                        "line": 2,
                        "column": 0
                    },
                    "end": {
                        "line": 3,
                        "column": 5
                    }
                },
                "range": [
                    9,
                    20
                ],
                "raw": "text1\ntext1"
            }
        ]
    },
    {
        "type": "Section",
        "range": [
            22,
            43
        ],
        "loc": {
            "start": {
                "line": 5,
                "column": 0
            },
            "end": {
                "line": 8,
                "column": 5
            }
        },
        "raw": "# Headertext2\ntext2",
        "children": [
            {
                "type": "Header",
                "depth": 1,
                "children": [
                    {
                        "type": "Str",
                        "value": "Header",
                        "loc": {
                            "start": {
                                "line": 5,
                                "column": 2
                            },
                            "end": {
                                "line": 5,
                                "column": 8
                            }
                        },
                        "range": [
                            24,
                            30
                        ],
                        "raw": "Header"
                    }
                ],
                "loc": {
                    "start": {
                        "line": 5,
                        "column": 0
                    },
                    "end": {
                        "line": 5,
                        "column": 8
                    }
                },
                "range": [
                    22,
                    30
                ],
                "raw": "# Header"
            },
            {
                "type": "Paragraph",
                "children": [
                    {
                        "type": "Str",
                        "value": "text2\ntext2",
                        "loc": {
                            "start": {
                                "line": 7,
                                "column": 0
                            },
                            "end": {
                                "line": 8,
                                "column": 5
                            }
                        },
                        "range": [
                            32,
                            43
                        ],
                        "raw": "text2\ntext2"
                    }
                ],
                "loc": {
                    "start": {
                        "line": 7,
                        "column": 0
                    },
                    "end": {
                        "line": 8,
                        "column": 5
                    }
                },
                "range": [
                    32,
                    43
                ],
                "raw": "text2\ntext2"
            }
        ]
    }
]
*/

Example

Changelog

See Releases page.

Running tests

Install devDependencies and Run npm test:

npm i -d && npm test

Contributing

Pull requests and stars are always welcome.

For bugs and feature requests, please create an issue.

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

Author

License

MIT © azu

Keywords

FAQs

Last updated on 15 Jan 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc