예제 #1
0
파일: mdoc.py 프로젝트: FernandoNobel/mdoc
def remove_intro(input, output):
    """ Parse the INPUT file through the remove double intros filter and
    generate the OUTPUT file

    This filter removes extra intros in the document. For example:

    \b
    \tThe following text:

    \t"This text has

    \tdouble intros"

    , will become:

    \b
    \t"This text has
    \tdouble intros"

    """

    # Read all the file to process
    data = input.read()

    # Set up the pipeline of filters.
    pipeline = Pipeline()

    pipeline.addFilter(RemoveExtraIntroFilter())

    # Run the pipeline.
    data = pipeline.run(data)

    # Write data into out file.
    output.write(data)
    output.flush()
예제 #2
0
파일: mdoc.py 프로젝트: FernandoNobel/mdoc
def include(input, output):
    """ Parse the INPUT file through the include text filter and generate the 
    OUTPUT file

    This filter includes text from other file. 

    \t @[ini,end](/path/to/file)

    With "ini" and "end" options you can specify to only include a part of the
    text to include. For example,

    \t @[ini:%% 1,end=%%](./myMatlab.m)

    Will include only the text between the first appearance of "%% 1" and the
    next "%%".
    
    """

    # Read all the file to process
    data = input.read()

    # Set up the pipeline of filters.
    pipeline = Pipeline()

    pipeline.addFilter(IncludeFileFilter())

    # Run the pipeline.
    data = pipeline.run(data)

    # Write data into out file.
    output.write(data)
    output.flush()
예제 #3
0
파일: mdoc.py 프로젝트: FernandoNobel/mdoc
def exec(input, output, no_exec):
    """ Parse the INPUT file through the execute code filter and generate the
    OUTPUT file

    This filter executes code and write the output of the execution in the file.

    \b
    \t ```LANGUAGE exec [OPTIONS]
    \t [Code to be execute]
    \t ```

    Where LANGUAGE is the programming language of the code. Currently only
    MATLAB and BASH code are supported. 

    Pro Tip: you can execute python code if you execute like a bash command:

    \b
    \t ```sh exec
    \t python3 myPythonProgramm.py
    \t ```

    OPTIONS

    \b
    \t --path /path/to/workspace 
    \t\t\t Define the workspace path.
    \t --no-code \t Do not return the code itself.
    \t --no-echo \t Do not return the result of the code.
    \t --raw \t\t Print the output of the command as it is, without the ```

    For example:

    \b
    \t ```sh exec --no-code --path /home/user/path/to/folder --raw
    \t ls
    \t ```

    This will print the contents of /home/user/path/to/folder as plain text
    without the code.
    """

    # Read all the file to process
    data = input.read()

    # Set up the pipeline of filters.
    pipeline = Pipeline()

    pipeline.addFilter(ExecuteCodeFilter(no_exec))

    # Run the pipeline.
    data = pipeline.run(data)

    # Write data into out file.
    output.write(data)
    output.flush()
예제 #4
0
파일: mdoc.py 프로젝트: FernandoNobel/mdoc
def parse(input, output, md, no_exec, intro):
    """ Parse the INPUT file through the pipeline and show the result in the
    stdout. There are options (-o, --md) for creating output files with the result.

    The pipeline is set by the following filters:

    \b
    \t 1. Comment filter
    \t 2. Include file filter
    \t 3. Table of contents filter
    \t 4. Execute code filter

    The input file is first processed by the first filter, the output of that
    filter is used as an input for the second filter and so on.
    """
    # Read all the file to process.
    data = input.read()

    # Set up the pipeline of filters.
    pipeline = Pipeline()

    pipeline.addFilter(CommentFilter())
    pipeline.addFilter(IncludeFileFilter())
    pipeline.addFilter(TableOfContentsFilter())

    pipeline.addFilter(ExecuteCodeFilter(no_exec))

    if intro:
        pipeline.addFilter(RemoveExtraIntroFilter())

    # Run the pipeline.
    data = pipeline.run(data)

    # If markdown flag is used, output the file as a originalName.md.
    if md:
        defaultName = os.path.splitext(input.name)[0] + '.md'
        output = open(defaultName, 'w')

    if output:
        # Write data into out file.
        output.write(data)
        output.flush()
        return

    print(data)
예제 #5
0
파일: mdoc.py 프로젝트: FernandoNobel/mdoc
def toc(input, output):
    """ Parse the INPUT file through the table of contents filter and
    generate the OUTPUT file

    This filter creates a table of contents from the headers defined in markdown
    style.

    To include a table of contents in your code you have to add:

    \t [TOC]

    , then it will search all the headers and subheaders and it will produce
    something like this:

    \b
    \t * [Introduction](#introduction)
    \t * [Table of contents](#table-of-contents)
    \t * [Installation](#installation)
    \t \t * [System requirement](#system-requirement)
    \t * [Usage](#usage)
    """

    # Read all the file to process
    data = input.read()

    # Set up the pipeline of filters.
    pipeline = Pipeline()

    pipeline.addFilter(TableOfContentsFilter())

    # Run the pipeline.
    data = pipeline.run(data)

    # Write data into out file.
    output.write(data)
    output.flush()
예제 #6
0
파일: mdoc.py 프로젝트: FernandoNobel/mdoc
def comment(input, output):
    """ Parse the INPUT file through the comment filter and generate the OUTPUT
    file

    This filter removes all text between the "<!--" and "-->" marks. For
    example:

    \b
    \tText to keep in the document.
    \t<!--
    \tText to remove.
    \tMore text to remove.
    \t-->
    \tText to also keep in the document.

    , will become:

    \b
    \tText to keep in the document.
    \tText to also keep in the document.
    """

    # Read all the file to process
    data = input.read()

    # Set up the pipeline of filters.
    pipeline = Pipeline()

    pipeline.addFilter(CommentFilter())

    # Run the pipeline.
    data = pipeline.run(data)

    # Write data into out file.
    output.write(data)
    output.flush()