Giter Club home page Giter Club logo

pancritic's Introduction

Build Status GitHub Releases PyPI version Development Status Python version

License Coveralls

Using CriticMarkup with pandoc. It serves both as a wrapper and a pre-processor.

Definition of CriticMarkup

  • Deletions: This is {--is --}a test.
  • Additions: This {++is ++}a test.
  • Substitutions: This {~~isn’t~>is~~} a test.
  • Highlighting: This is a {==test==}.
  • Comments: This is a test{>>What is a test for?<<}.

Installation

Install using

pip install pancritic

Usage: pancritic as a markdown wrapper (including but not limited to pandoc)

pancritic provides a pandoc-like cli. Pandoc users will feel right at home. See help from

pancritic -h

A typical use of pancritic will be like

pancritic -s -o index.html index.md

See examples in HTML and PDF.

pancritic specific options

  • --engine
    The default engine is markdown. Valid options are markdown, markdown2, panflute, pypandoc. You need to install the respective package in order to use them. markdown and markdown2 are pure Python, hence useful for other CPU architechture. panflute and pypandoc both uses pandoc as backend.

  • -m|--critic-mode
    a/accept, r/reject: accept/reject changes.

    d/diff: generates a diff. In HTML output, JS is used for toggling between diff, accept, reject.

    m/markup: treat the CriticMarkup as Markup. i.e. in HTML output there isn’t any toggles but the diff view only. In LaTeX output, diff and markup modes are identical except for an additional nav. -m m should be used with LaTeX output.

Previous Users

Previous Users of pandoc-criticmarkup

This is completely rewritten in Python. The cli has been completely changed too. The former options of -a, -r, -d are replaced with -m a, -m r, -m d, and added a -m m.

Previous Users of criticParser_CLI.py

This is a heavy fork of criticParser_CLI.py, with these differences:

  1. CLI has changed, with a more pandoc-like interface.
  2. Python 3 (and 2) compatible.
  3. Bug fixes (formerly hightlight without comment are parsed incorrectly).
  4. It has much more input/output format options as well as engines.

Examples,

criticParser_CLI.py input.md -m2 -o output.html --css css.html
# is equivalent to
pancritic -o output.html input.md --critic-template css.html --engine markdown2

Advanced Usage: pancritic as a pandoc preprocessor

A somewhat surprising behavior is when the to-format and output extension is different. In pancritic, the to-format indicates the CriticMarkup parsing behavior (mainly tex vs. html). And the output extension controls the final output’s format (e.g. markdown, html, etc.)

An interesting use of this is to use pancritic as a pandoc preprocessor instead, like this

pancritic input.md -t markdown -m m | pandoc -s -o output.html

This will be useful if more advanced pandoc args are needed.

Caveats

  • Nesting CriticMarkup might have unexpected behavior, especially in LaTeX output. See the caveats section in the spec of CriticMarkup.

  • mainly tested with HTML and LaTeX output. RST output almost works, but injecting CSS/JS into the output causes some problems. Currently, it can be get arround with --critic-template and injecting the CSS/JS manually. See pancritic/template.py for the template used.

LaTeX Ouptut

Note that the LaTeX output requires the LaTeX packages changes>=3.[1]

One can tell pandoc to use this package by either using a custom template or --include-in-header option. Or you can use the trick of putting the following in your YAML front matter, like this file:

---
fontfamily: lmodern,changes
...

Markdown within the CriticMarkup will not be rendered in LaTeX output. If you want to change this behavior, you can take a look at: LaTeX Argument Parser.

CriticMarkup LaTeX
{--[text]--} \deleted{[text]}
{++[text]++} \added{[text]}
{~~[text1]~>[text2]~~} \replaced{[text2]}{[text1]}
{==[text]==} \highlight{[text]}
{>>[text]<<} \comment{[text]}

Translation from CriticMarkup to LaTeX.

Credits

  1. The version of the package in TeXLive 2018 is still v2. TeXLive 2019 should be available on 2019-4-30, meanwhile you need to

    # sudo is needed in most cases, depending on where you put it
    sudo tlmgr update --self
    sudo tlmgr update changes
    # check it is >=3
    tlmgr info changes

pancritic's People

Contributors

alerque avatar ickc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

zaxebo1 alerque

pancritic's Issues

Cannot create PDFs

I have installed pancritic and pypandoc (and later panflute as well) into a virtual environment. pandoc itself is installed and on the path.

When I issue

pancritic -t latex -o scr.pdf scr.md

I get the message

Cannot use pypandoc.
Use panflute instead.
Cannot use panflute.
Stop converting and output original format instead

and no output.

What's going wrong?

Add option to output Critic Markup

In the current iteration Critic Markup is treated as a one way street — touch it and it's gone. You can output to HTML or LaTeX. Outputting to Markdown only adds inline HTML tags to the Markdown option.

There should be an output option for outputting Markdown with Critic Markup syntax back in place. In other words it should be possible to round-trip between formats.

See also jgm/pandoc#5430.

The engine flag is not reliable

The --engine flag needs some help.

  1. It is never clear which backend was actually used. I have all the possible ones available on my system, but which one is actually used is a mystery. This is frustrating to debug in light of point 2. Some kind of debug flag should be introduced that notes what engine was actually used, probably to a message on stderr.

  2. Setting an bogus engine does not result in an error:

    ❯ pancritic -f markdown -t latex --critic-mode markup --engine aoeu - <<< "test"
    No output file extension nor to-format specified. Default to HTML.
    <p>test</p>

    Really, aoeu is a valid engine and scored me real output‽ But wait, the plot thickens. It didn't just ignore me outright on the invalid engine, something changed because if you leave off the flag off you get something else:

    ❯ pancritic -f markdown -t latex --critic-mode markup - <<< "test"
    No output file extension nor to-format specified. Default to HTML.
    
    <style>
    ....
    </style>
    <script>
    ....
    </script>
    
    
    <div id="wrapper">
    
    <p>test</p>
    
    </div>
    <p>test</p>

    Of course neither of these output are actually LaTeX (see #5), they are both HTML. But strangely one of them is just the inline content, the other is wrapped (as in this is almost a hack for #7).

    Setting an invalid engine should be an error. Falling back to something other than the one specified should be a warning.

Option to include "ch"-Prefix in latex

The changes-latex-package offers the option to add the "ch"-Prefix to commands. Thus \added becomes \chadded and so forth. This is supposed to fix conflicts with other packages, in particular regarding \comment and \highlight.

It would be nice to have such a flag in pancritic too.

Right now I'm using a lua-filter for my further pandoc-generation, which transforms occurences of \added to \chadded (and so on). But this is error-prone and probably also takes away some extra performance unnecessarily.

Travis tests frequently die, possible rate limit issue

I was trying to see if my PRs were passing tests, and it looks like the Travis CI runs are failing semi randomly about half the time. The culprit seems to be this bit:

install: 
 - downloadUrl=$(python -c 'import requests, sys; v = sys.argv[1]; url = "https://api.github.com/repos/jgm/pandoc/releases/" + (v if v == "latest" else ("tags/" + v)); print(next(i["browser_download_url"] for i in requests.get(url).json()["assets"] if i["name"][-3:] == "deb"))' $pandocVersion) && wget $downloadUrl && sudo dpkg -i ${downloadUrl##*/}

Testing it locally seems to work okay.

One guess is that Github might be rate limiting unauthenticated requests to this API.

parsing docx input with "track changes"

I'm testing out pancritic on ubuntu.

pip3 install --upgrade pancritic
Running pancritic-0.2
chapter1.docx

python3 -m pancritic chapter1.docx -t markdown -m m
(just to make doubly sure I'm not having any python2 problems)

Throws an error: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xad in position 41: invalid start byte

brian@1602019:~/testSupervisorComments$ pancritic chapter1.docx
Traceback (most recent call last):
  File "/home/brian/.local/bin/pancritic", line 11, in <module>
    sys.exit(cli())
  File "/home/brian/.local/lib/python3.6/site-packages/pancritic/main.py", line 137, in cli
    main(*get_args())
  File "/home/brian/.local/lib/python3.6/site-packages/pancritic/main.py", line 103, in get_args
    body = args.input.read()
  File "/usr/lib/python3.6/codecs.py", line 321, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xad in position 41: invalid start byte

Is this a bug on my end?

relicense to BSD 3-Clause License

@alerque, sorry for the spam and frankly I haven't maintained this much lately. Similar to ickc/pantable#50, I'm just trying to relicense this into a more permissive license for formality (not that it may have a real impact...)

Let me know if I have your permission, as you're the only other contributor here so far. Thanks.

Use as preprocessor error

I was trying to use pancritic as a preprocessor for pandoc using
pancritic docum1.md -t markdown -m a | pandoc -s -o docum1.pdf
but got the following error.
I was planning to apply --filters in pandoc.
I am wondering the correct way of using it as a preprocessor.

Traceback (most recent call last):
File "/usr/local/bin/pancritic", line 11, in
sys.exit(cli())
File "/usr/local/lib/python2.7/site-packages/pancritic/main.py", line 137, in cli
main(*get_args())
File "/usr/local/lib/python2.7/site-packages/pancritic/main.py", line 117, in get_args
output_format = normalize_format(os.path.splitext(args.output)[1][1:])
File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/posixpath.py", line 98, in splitext
return genericpath._splitext(p, sep, altsep, extsep)
File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/genericpath.py", line 99, in _splitext
sepIndex = p.rfind(sep)
AttributeError: 'NoneType' object has no attribute 'rfind'

Need option to not include wrapper

Similar to #6, I am trying to use the output in the context of a system that understands what to do with the resulting inline markup. I don't want to wrap the document in <div id="wrapper"></div>. There should be a command line flag to now wrap the output. In fact I would argue that this should be the default, and adding a wrapper should be the option (similar to pandoc --standalone).

Cannot use markdown

pancritic always reports a Cannot use markdown error.

Input test.md:

{~~Hello~>Goodbye~~} World
==========================

Hi. This is me. Hello me!

-   Apple
-   {~~Banana~>Boysenberries~~}
-   Cucumber
-   {++Dogs++}

Ok.{++ This is pretty good.++}

{--Goodbye.--}

{++Hello.++}

Execute:

2831)Documents % pancritic -s -m m test.md -o test.html
Cannot use markdown.
Use markdown2 instead.
Cannot use markdown2.
Stop converting and output original format instead.

The output is, indeed, an HTML with CSS and Javascript, so it's basically working. The error message is confusing and I don't know what other problems it may be masking.

OSX High Sierra; pancritic installed via pip (v18.1, Python 3.7).

Warning messages should not be on stdout

Several warning messages (e.g. not setting the input or output file types, defaulting to HTML) are output to stdout that should be sent to stderr instead. This would allow CLI usage in a shell pipeline to get the warnings to the user without dirtying up the actual contents of the pipeline.

Need option to not include styles

Including the css style sheet in both HTML and Markdown output options is obnoxious in the context of a larger system designed to handle the markup other ways.

Using --critic-template /dev/null works but is a bit of a hack. A dedicated option for this would be a lot easier to use and "discover".

Undefined control sequence. \hl

With the -d pdf flag I get

Undefined control sequence.  
   \hl

Actually added a \newcommand{\hl}[1]{\colorbox{yellow}{#1}} somewhere in the text. But the error persists. It is however possible to use the \hl and colour text by hand.

To flag does not work as advertized

The --help and readme both mention a -t / --to flag to specify the output format. The readme also includes an example of using pandcritic as a preprocessor. This is exactly what I want to to, but the flag does not actually function as advertised.

$ pancritic - -f markdown -t markdown -m m --critic-template /dev/null <<< "test"
No output file extension nor to-format specified. Default to HTML.


<div id="wrapper">

<p>test</p>

</div>

Note the -f / --from flag does work correctly for the input side of things, and specifying an output file name with -o something.md also works to auto-detect the to format. What cannot be done as advertised is pipe the output into pandoc or anything else as markdown.

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.