Giter Site home page Giter Site logo

linkedtext's Introduction

linkedText

It allows to create a table of contents and link them to the different titles of a Markdown document, without altering the original file and generating a new one.

The idea came up to automate this manual process, it was tedious to write and check that each title has its link and create the table of contents. Now I simply write the content, run the program and I have the finished document.

Installation

$ pip install linkedtext

Usage CLI

  1. Help
usage: linkedtext [-h] -f FILENAME

options:
  -h, --help            show this help message and exit
  -f FILENAME, --filename FILENAME
                        Markdown file.
  1. In the terminal
$ linkedtext -f path/my_file.md

Usage - Python

The LinkedText class supports both Markdown files (markdown_file parameter) and strings in Markdown format (string parameter).

  • Markdown file

When passing a Markdown file, it will be parsed and processed, generating a new file with the same name as the original and ending with _finish. The original file is never altered. Writing is automatic.

>>> from linkedtext import LinkedText
>>>
>>> c = LinkedText(markdown_file='my_file.md')
>>> c.process()
>>> c.to_write()
  • Markdown string

When a Markdown string is used, the result will be displayed in the terminal, it can be written to a file, this will be named linkedtext_finish.md by default.

>>> from linkedtext import LinkedText
>>>
>>> c = LinkedText(string=string_markdown)
>>> c.process()
>>> c.to_write()

Sample

  • String Markdown
string = """
# First

First paragraph.

## Second

Second paragraph.

# Third

Third paragraph.


# Fourth

Fourth paragraph.
"""

from linkedtext import LinkedText

c = LinkedText(string=string)
c.process()
# c.to_write()   # write to the `linkedtext_finish.md` file.
  • Output
1. [First](#first)
    1. [Second](#second)
2. [Third](#third)
3. [Fourth](#fourth)

\pagebreak


<a name="first"></a>

# First

First paragraph.

<a name="second"></a>

## Second

Second paragraph.

<a name="third"></a>

# Third

Third paragraph.


<a name="fourth"></a>

# Fourth

Fourth paragraph.

Tests

. run_tests.sh
# or
python -m unittest

linkedtext's People

Contributors

kurotom avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.