Git Product home page Git Product logo

tidy-markdown's Introduction

Tidy Markdown

Build Status NPM version NPM license

Beautify Markdown, fixing formatting mistakes and converting basic HTML & Unicode into their Markdown equivalents. Based on the conventions in Carrot Creative's Markdown Styleguide and built on Marked.

There is also an Atom Plugin to run this entirely within your editor.

Install

Tidy Markdown is an npm package, so it can be installed like this:

npm install tidy-markdown -g

CLI

Tidy Markdown includes a simple CLI. It operates entirely over STDIN/STDOUT. For example:

$ echo "# a header #" | tidy-markdown
# a header

Or using a file:

$ tidy-markdown < ./ugly-markdown
# Some markdown

Lorem ipsum dolor adipiscing

- one
- two
- three

And, of course, we can output to a file too:

$ tidy-markdown < ./ugly-markdown > ./clean-markdown

Editing In-place

If you want to rewrite a file in-place, you can use sponge from moreutils. If you did tidy-markdown < ./README.md > ./README.md you'd end up with an empty file.

$ tidy-markdown < ./README.md | sponge ./README.md

Docs

The --help arg will make it show a usage page:

$ tidy-markdown --help
usage: tidy-markdown [-h] [-v] [--no-ensure-first-header-is-h1]

Fix ugly markdown. Unformatted Markdown is read from STDIN, formatted, and
written to STDOUT.

Optional arguments:
  -h, --help            Show this help message and exit.
  -v, --version         Show program's version number and exit.
  --no-ensure-first-header-is-h1
                        Disable fixing the first header when it isn't an H1.
                        This is useful if the markdown you're processing
                        isn't a full document, but rather a piece of a larger
                        document.

API

Tidy Markdown only exports one function. Here's an example of how it can be used:

tidyMarkdown = require 'tidy-markdown'

uglyMarkdown = '''
# Some markdown #

Lorem ipsum dolor adipiscing


- one
*  two
+ three
'''

cleanMarkdown = tidyMarkdown(uglyMarkdown)
console.log cleanMarkdown

which outputs:

# Some markdown

Lorem ipsum dolor adipiscing

- one
- two
- three

You can also pass options through a 2nd arg, like tidyMarkdown(uglyMarkdown, {ensureFirstHeaderIsH1: false}). The option ensureFirstHeaderIsH1 is the only one right now.

Features

  • Standardize syntactical elements to use a single way of being written (for example, all unordered lists are formatted to start with hyphens, rather than allowing asterisks and/or addition signs to be mixed in).
  • Fix numbering - making ordered lists count naturally from 1 to n and reference links do the same (based on first occurance).
  • Make headers move from h1 to smaller without gaps (like an h1 followed by an h4 would be corrected to an h1 followed by an h2).
  • Decode Unicode characters that have markdown equivalents (like a horizontal ellipsis becomes "..." and an em-dash becomes "--").
  • Format YAML front-matter and Markdown tables.
  • Convert HTML elements into their Markdown equivalents. For example, <em>text</em> becomes _text_.

Minimal Configuration

Tidy Markdown works hard to keep configuration to a minimum. The goal is to create a highly readable, canonical representation of Markdown, much like gofmt has done for Go. Having extra configuration would defeat that purpose and add extra maintenance work.

That's not to say you shouldn't open issues if you find the output ugly, that's encouraged, especially in the styleguide repo because without criticism it won't get better. However, you should provide examples and a good argument to support the change.

tidy-markdown's People

Contributors

buonomo avatar kent-mcleod avatar notslang 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  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

tidy-markdown's Issues

fix number should be optional

Adding numbers to Markdown files makes for unnecessary diffs when adding new items part way down a numbered list. I vote for fix number to either be removed or optional. An added bonus would be the have the opposite of fix number where it actually makes all numbers 1.

Uncaught while scanning for the next token found character ` that cannot start any token on line 3, column 1

[Enter steps to reproduce below:]

  1. edit a markdown text looking like this

Hébergement :

Motel 6 Chambre 248 3900 E Mulberry St, Fort Collins, CO 80524 67.30 USD

  1. save, it crashes
  2. if I remove the codeblock, it works.

Atom Version: 1.0.7
System: Mac OS X 10.10.4
Thrown From: tidy-markdown package, v1.0.0

Stack Trace

Uncaught while scanning for the next token
found character ` that cannot start any token
on line 3, column 1

At /Applications/Atom.app/Contents/Resources/app.asar/src/pane.js:801

while scanning for the next token
found character ` that cannot start any token
  on line 3, column 1
  at ScannerError.YAMLError (/Users/sw/.atom/packages/tidy-markdown/node_modules/tidy-markdown/node_modules/front-matter/node_modules/yaml-js/lib/errors.js:70:46)
  at ScannerError.MarkedYAMLError (/Users/sw/.atom/packages/tidy-markdown/node_modules/tidy-markdown/node_modules/front-matter/node_modules/yaml-js/lib/errors.js:90:45)
  at new ScannerError (/Users/sw/.atom/packages/tidy-markdown/node_modules/tidy-markdown/node_modules/front-matter/node_modules/yaml-js/lib/scanner.js:23:49)
  at Constructor.Scanner.Scanner.fetch_more_tokens (/Users/sw/.atom/packages/tidy-markdown/node_modules/tidy-markdown/node_modules/front-matter/node_modules/yaml-js/lib/scanner.js:241:13)
  at Constructor.Scanner.Scanner.check_token (/Users/sw/.atom/packages/tidy-markdown/node_modules/tidy-markdown/node_modules/front-matter/node_modules/yaml-js/lib/scanner.js:116:14)
  at Constructor.Parser.Parser.parse_block_mapping_value (/Users/sw/.atom/packages/tidy-markdown/node_modules/tidy-markdown/node_modules/front-matter/node_modules/yaml-js/lib/parser.js:447:19)
  at Constructor.Parser.Parser.check_event (/Users/sw/.atom/packages/tidy-markdown/node_modules/tidy-markdown/node_modules/front-matter/node_modules/yaml-js/lib/parser.js:62:48)
  at Constructor.Composer.Composer.compose_node (/Users/sw/.atom/packages/tidy-markdown/node_modules/tidy-markdown/node_modules/front-matter/node_modules/yaml-js/lib/composer.js:73:16)
  at Constructor.Composer.Composer.compose_mapping_node (/Users/sw/.atom/packages/tidy-markdown/node_modules/tidy-markdown/node_modules/front-matter/node_modules/yaml-js/lib/composer.js:146:27)
  at Constructor.Composer.Composer.compose_node (/Users/sw/.atom/packages/tidy-markdown/node_modules/tidy-markdown/node_modules/front-matter/node_modules/yaml-js/lib/composer.js:92:21)
  at Constructor.Composer.Composer.compose_document (/Users/sw/.atom/packages/tidy-markdown/node_modules/tidy-markdown/node_modules/front-matter/node_modules/yaml-js/lib/composer.js:65:19)
  at Constructor.Composer.Composer.get_single_node (/Users/sw/.atom/packages/tidy-markdown/node_modules/tidy-markdown/node_modules/front-matter/node_modules/yaml-js/lib/composer.js:52:25)
  at Constructor.BaseConstructor.BaseConstructor.get_single_data (/Users/sw/.atom/packages/tidy-markdown/node_modules/tidy-markdown/node_modules/front-matter/node_modules/yaml-js/lib/constructor.js:77:19)
  at Object.load (/Users/sw/.atom/packages/tidy-markdown/node_modules/tidy-markdown/node_modules/front-matter/node_modules/yaml-js/lib/yaml.js:112:20)
  at parse (/Users/sw/.atom/packages/tidy-markdown/node_modules/tidy-markdown/node_modules/front-matter/index.js:28:27)
  at extractor (/Users/sw/.atom/packages/tidy-markdown/node_modules/tidy-markdown/node_modules/front-matter/index.js:21:34)
  at module.exports (/Users/sw/.atom/packages/tidy-markdown/node_modules/tidy-markdown/lib/index.coffee:274:13)
  at Object.module.exports.run (/Users/sw/.atom/packages/tidy-markdown/lib/index.coffee:49:17)
  at /Users/sw/.atom/packages/tidy-markdown/lib/index.coffee:30:12
  at TextBuffer.module.exports.TextBuffer.transact (/Applications/Atom.app/Contents/Resources/app.asar/node_modules/text-buffer/lib/text-buffer.js:755:18)
  at /Users/sw/.atom/packages/tidy-markdown/lib/index.coffee:28:14
  at Emitter.module.exports.Emitter.emit (/Applications/Atom.app/Contents/Resources/app.asar/node_modules/event-kit/lib/emitter.js:82:11)
  at TextBuffer.module.exports.TextBuffer.saveAs (/Applications/Atom.app/Contents/Resources/app.asar/node_modules/text-buffer/lib/text-buffer.js:1000:20)
  at TextBuffer.module.exports.TextBuffer.save (/Applications/Atom.app/Contents/Resources/app.asar/node_modules/text-buffer/lib/text-buffer.js:992:19)
  at TextEditor.module.exports.TextEditor.save (/Applications/Atom.app/Contents/Resources/app.asar/src/text-editor.js:579:26)
  at Pane.module.exports.Pane.saveItem (/Applications/Atom.app/Contents/Resources/app.asar/src/pane.js:539:18)
  at Pane.module.exports.Pane.saveActiveItem (/Applications/Atom.app/Contents/Resources/app.asar/src/pane.js:522:19)
  at Workspace.module.exports.Workspace.saveActivePaneItem (/Applications/Atom.app/Contents/Resources/app.asar/src/workspace.js:609:35)
  at atom-workspace.atom.commands.add.core:save (/Applications/Atom.app/Contents/Resources/app.asar/src/workspace-element.js:293:30)
  at CommandRegistry.module.exports.CommandRegistry.handleCommandEvent (/Applications/Atom.app/Contents/Resources/app.asar/src/command-registry.js:241:29)
  at /Applications/Atom.app/Contents/Resources/app.asar/src/command-registry.js:3:61
  at KeymapManager.module.exports.KeymapManager.dispatchCommandEvent (/Applications/Atom.app/Contents/Resources/app.asar/node_modules/atom-keymap/lib/keymap-manager.js:524:16)
  at KeymapManager.module.exports.KeymapManager.handleKeyboardEvent (/Applications/Atom.app/Contents/Resources/app.asar/node_modules/atom-keymap/lib/keymap-manager.js:347:22)
  at HTMLDocument.module.exports.WindowEventHandler.onKeydown (/Applications/Atom.app/Contents/Resources/app.asar/src/window-event-handler.js:177:20)

Commands

     -0:41.7.0 core:save (atom-text-editor.editor.is-focused)
  2x -0:24.7.0 markdown-writer:insert-new-line (atom-text-editor.editor.is-focused)
     -0:23.3.0 fuzzy-finder:toggle-file-finder (atom-text-editor.editor.is-focused)
     -0:22.5.0 editor:consolidate-selections (atom-text-editor.editor.mini.is-focused)
     -0:22.5.0 core:cancel (atom-text-editor.editor.mini.is-focused)
     -0:21.5.0 fuzzy-finder:toggle-file-finder (atom-text-editor.editor.is-focused)
     -0:18.4.0 editor:consolidate-selections (atom-text-editor.editor.mini.is-focused)
     -0:18.4.0 core:cancel (atom-text-editor.editor.mini.is-focused)
     -0:16.5.0 autocomplete-plus:confirm (atom-text-editor.editor.is-focused.autocomplete-active)
     -0:16.5.0 snippets:expand (atom-text-editor.editor.is-focused.autocomplete-active)
  3x -0:15.7.0 core:save (atom-text-editor.editor.is-focused)

Config

{
  "core": {}
}

Installed Packages

# User
markdown-writer, v1.8.1
tidy-markdown, v1.0.0

# Dev
No dev packages

Add hard wrap option

Long lines are ugly in diffs. But editing can be a pain, too. For example an enumeration with long items:

Without soft wrapping:

1. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. 
2. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. 

With soft wrapping:

1. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor  invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. 
2. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, 
no sea takimata sanctus est Lorem ipsum dolor sit amet. 

With formatted hard wrapping:

1. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
   tempor  invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. 
2. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, 
   no sea takimata sanctus est Lorem ipsum dolor sit amet. 

Email addresses being converted to mailto: links

I'm not entirely sure if I'm correct here, but I typed: <[email protected]> and it got converted to [[email protected]](mailto:[email protected]) which I just double-checked might not be correct.

Reference: https://daringfireball.net/projects/markdown/syntax (search for "@" for the email address examples)

I was looking through the code and couldn't find the specific case where tidy-markdown is causing this to occur, otherwise I'd have tried to make a pull request for you.

Should not convert links

Links like

https://github.com/slang800/atom-tidy-markdown/issues/new

are converted into

[https://github.com/slang800/atom-tidy-markdown/issues/new](https://github.com/slang800/atom-tidy-markdown/issues/new)

which is completely unnecessary and reduces readability by increasing the length of. So this should not done anymore or there should be at least a checkbox to deselect this.


Moved from notslang/atom-tidy-markdown#28

Limit line length

For paragraphs, limit their line lengths to some configurable value e.g. 80 or -1 to make it infinite. Only applies to paragraph blocks.

How can I personally DISABLE filter: 'img' from converters.coffee

How can I personally DISABLE filter: 'img' from converters.coffee so my Atom doesn't smash my <img> tags when I hit save?

I'm sorry but I don't see a "How to Customize your tidy-markdown" section.

Your code in your converters.coffee

{
    filter: 'img'
    surroundingBlankLines: false
    replacement: (content, node, links) ->
      alt = getAttribute(node, 'alt') or ''
      url = getAttribute(node, 'src') or ''
      title = getAttribute(node, 'title')
      referenceLink = _.find(links, {url, title})
      if referenceLink
        if alt.toLowerCase() is referenceLink.name
          "![#{alt}]"
        else
          "![#{alt}][#{referenceLink.name}]"
      else if title
        "![#{alt}](#{url} \"#{title}\")"
      else
        "![#{alt}](#{url})"
  }

I just want to disable this somehow in Atom so I can commit <img> tags to my README.md file.

Can I disable just this this one filter or do I have to turn off tidy-markdown all together?

Thanks,
Scott

Don't enforce H1 as the first header when front matter present

A follow up to #4, while I agree (and really like) the idea of enforcing all documents to begin with an H1 (and then must go in order after that), often when writing a Jekyll post or page, there will be implicit H1s and H2s in the template (site and page title), and the first-level available to the post content should really be an H3.

Would it be possible to disable the H1 must be the top level header check if front-matter is present? At least in my mind, front matter denotes some sort of templating engine, for which the markdown file will be a partial, not an entire document.

On a related note, this library is great. It (and the Atom package) is exactly what I've been looking for for years and am going to be sending lots of folks this way (at GitHub we use markdown for everything). 😄

[query] Is output valid CommonMark?

Do you make any guarantees that the output conforms to the CommonMark spec? It doesn't look like it, just thought I'd confirm.

I understand that a document with tables obviously wouldn't conform (last I checked tables weren't in CommonMark).

Can't resolve modules

Installed, imported. Getting these errors..
Can't resolve '../lib/language-code-rewrites'
Module not found: Error: Can't resolve './block-tags'
Module not found: Error: Can't resolve './void-tags'

Getting tidy-markdown to leave this TOC Markdown untouched

Description

Background:

I am using the Jekyll Documentation Theme for a project. It uses a piece of Markdown for setting up the table of contents on a page.

* Table of Contents
{:toc}

Problem:

Need to get Tidy Markdown (in use as an atom-beautify plugin) to leave it untouched. The beautified code doesn't play well with Jekyll. Is there a way to tell Tidy Markdown not to reformat this?

I have played with the settings but cannot get it to work. I have posted some debug information. If more information would help, I am happy to try to obtain it, but might need some guidance on obtaining it.

Is this a bug? If not, any workaround?

PS: I am new to Markdown

Input Before Beautification

This is what the code looked like before:

* Table of Contents
{:toc}

Expected Output

The beautified code should have remained like this:

* Table of Contents
{:toc}

Actual Output

The beautified code actually looked like this:

Using Tidy-Markdown:

- Table of Contents {:toc}

Loses formatting

Common motivations for using HTML tables

  • vertical alignment control
  • fore and background colour control
  • colspan/rowspan

In all of these cases the use of HTML is intentional and conversion to markdown is destructive.

So don't convert these cases.

*italic_text* converted to _italic_text_ on saving

When I save something in italic using * char, I don’t really care about this changing to _. However sometimes it creates issues, like with this simple_example (github flavoured markdown fixes it as I see right now)!
Maybe changing char should be an option, what do you think of it ?

Support for numeric lists

Input

- item
-  item
-   item

1. one
2.  two
2.   three

Preview

  • item
  • item
  • item
  1. one
  2. two
  3. three

Expected Output

- item
- item
- item

1. one
2. two
2. three

Current (wrong) Output

- item
- item
- item
- one
- two
- three

Notice how it removes the list item's numbering (1,2,3.).

/cc Glavin001/atom-beautify#292

Bug with Numbered Lists and Bulleted Lists

There appears to be a bug with list handling. I am using atom-beautify in atom, which is using tidy-markdown for markdown support.

If I start with this:

1. Do this first
2. And then this

- Bucket
- List

The first time I run tidy-markdown, I get this:

1. Do this first
- And then this
- Bucket
2. List

The above renders to a numbered list when parsed. So, as expected, the markdown is converted to this when I run tidy-markdown a second time:

1. Do this first
2. And then this
3. Bucket
4. List

Nested lists are handled correctly. The following is not modified when tidy-markdown is run.

1. Do this first
2. And then this
  - Bucket
  - List

It seems the solution to this would be to differentiate between numbered lists and bulleted lists and not attempt to merge them.

Add option to have more newlines before list

A lot of markdown parsers break with input that looks like

This is my paragraph.
- and this
- is 
- a
- list

and expect Markdown that looks more like:

This is my paragraph.

- and this
- is 
- a
- list

This should be allowed at least with an flag.

Auto delete blockquotes empty line

eg. (1) > > >
(2) > > > 1. a
(3) > > >  
result. (1) del (2) no change (3) del
so if i can't ignore this i can not use Beautify On Save lazy

Problems adding escaped pipes in tables

From @derek-austin in notslang/atom-tidy-markdown#62

Please add an option to disable HTML escapes substitution

Use case for the option:

If you have 'Run on Save' and save this

Command | Description
------- | ------------------------
ls      | list directory contents 
ls | wc | count directory contents
ls \| wc | count directory contents
ls &#124; wc | count directory contents 

you get this

Command | Description
------- | ------------------------
ls      | list directory contents
ls      | wc                       | count directory contents
ls \    | wc                       | count directory contents
ls | wc | count directory contents

if you save it again you get this:

Command | Description
------- | -----------------------
ls      | list directory contents
ls      | wc                      | count directory contents
ls \    | wc                      | count directory contents
ls      | wc                      | count directory contents

If you disable the HTML escape substitution you could use the &#124; hack to render the table.

Bullets inside numbered lists and subbullets in bullets don't beatify correctly

Notice how these do not render equivalently.

Original
1. something
1. something
  - bullet
  - bullet
1. something
1. something

hi

Beautified
1. something
1. something

  - bullet
  - bullet

1. something
1. something

hi

Original

  1. something
  2. something
  • bullet
  • bullet
    1. something
    2. something

hi

Beautified

  1. something
  2. something
  • bullet
  • bullet
  1. something
  2. something

hi

Original
- something
- something
  - bullet
  - bullet
- something
- something

hi

Beautified
- something
- something

  - bullet
  - bullet

- something
- something

hi

Original

  • something
  • something
    • bullet
    • bullet
  • something
  • something

hi

Beautified

  • something
  • something
    • bullet
    • bullet
  • something
  • something

hi

Related to an issue I filled on GitLab at https://gitlab.com/gitlab-org/gitlab-ce/issues/23972 where they are rendered even more differently.

could not determine a constructor for the tag tag:yaml.org,2002:js/regexp

Input

---

title: This is a title!

name: Derek Worthen
age: young
contact:
email: [email protected]
address: some location
pets:
- cat
- dog
- bat
match: !!js/regexp /pattern/gim
run: !!js/function function() { }



---

- item
-  item
-   item

1. one
2.  two
2.   three

Expected Output

This is from Pandoc.

---
title: "This is a title!"
name: Derek Worthen
age: young
contact: null
email: "[email protected]"
address: some location
pets:
  - cat
  - dog
  - bat
match: !<tag:yaml.org,2002:js/regexp> /pattern/gmi
run: !<tag:yaml.org,2002:js/function> "function () {\n   \n}"

---

-   item
-   item
-   item

1.  one
2.  two
3.  three

Current Output

It errors.

could not determine a constructor for the tag tag:yaml.org,2002:js/regexp
on line 12, column 8
at ConstructorError.YAMLError (/Users/glavin/Documents/Project Dev/atom-beautify/node_modules/tidy-markdown/node_modules/front-matter/node_modules/yaml-js/lib/errors.js:70:46)
at ConstructorError.MarkedYAMLError (/Users/glavin/Documents/Project Dev/atom-beautify/node_modules/tidy-markdown/node_modules/front-matter/node_modules/yaml-js/lib/errors.js:90:45)
at new ConstructorError (/Users/glavin/Documents/Project Dev/atom-beautify/node_modules/tidy-markdown/node_modules/front-matter/node_modules/yaml-js/lib/constructor.js:17:53)
at Constructor.Constructor.construct_undefined (/Users/glavin/Documents/Project Dev/atom-beautify/node_modules/tidy-markdown/node_modules/front-matter/node_modules/yaml-js/lib/constructor.js:550:13)
at Constructor.BaseConstructor.BaseConstructor.construct_object (/Users/glavin/Documents/Project Dev/atom-beautify/node_modules/tidy-markdown/node_modules/front-matter/node_modules/yaml-js/lib/constructor.js:133:28)
at Constructor.BaseConstructor.BaseConstructor.construct_mapping (/Users/glavin/Documents/Project Dev/atom-beautify/node_modules/tidy-markdown/node_modules/front-matter/node_modules/yaml-js/lib/constructor.js:173:22)
at Constructor.Constructor.construct_mapping (/Users/glavin/Documents/Project Dev/atom-beautify/node_modules/tidy-markdown/node_modules/front-matter/node_modules/yaml-js/lib/constructor.js:294:54)
at /Users/glavin/Documents/Project Dev/atom-beautify/node_modules/tidy-markdown/node_modules/front-matter/node_modules/yaml-js/lib/constructor.js:521:23
at Constructor.BaseConstructor.BaseConstructor.construct_document (/Users/glavin/Documents/Project Dev/atom-beautify/node_modules/tidy-markdown/node_modules/front-matter/node_modules/yaml-js/lib/constructor.js:88:41)
at Constructor.BaseConstructor.BaseConstructor.get_single_data (/Users/glavin/Documents/Project Dev/atom-beautify/node_modules/tidy-markdown/node_modules/front-matter/node_modules/yaml-js/lib/constructor.js:79:21)
at Object.load (/Users/glavin/Documents/Project Dev/atom-beautify/node_modules/tidy-markdown/node_modules/front-matter/node_modules/yaml-js/lib/yaml.js:112:20)
at parse (/Users/glavin/Documents/Project Dev/atom-beautify/node_modules/tidy-markdown/node_modules/front-matter/index.js:28:27)
at extractor (/Users/glavin/Documents/Project Dev/atom-beautify/node_modules/tidy-markdown/node_modules/front-matter/index.js:21:34)
at module.exports (/Users/glavin/Documents/Project Dev/atom-beautify/node_modules/tidy-markdown/lib/index.js:304:15)
at module.exports.TidyMarkdown.beautify (/Users/glavin/Documents/Project Dev/atom-beautify/src/beautifiers/tidy-markdown.coffee:13:29)
at tryCatcher (/Users/glavin/Documents/Project Dev/atom-beautify/node_modules/bluebird/js/main/util.js:24:31)
at Promise.module.exports.Promise._resolveFromResolver (/Users/glavin/Documents/Project Dev/atom-beautify/node_modules/bluebird/js/main/promise.js:427:31)
at new Promise (/Users/glavin/Documents/Project Dev/atom-beautify/node_modules/bluebird/js/main/promise.js:53:37)
at TidyMarkdown.module.exports.TidyMarkdown.beautify (/Users/glavin/Documents/Project Dev/atom-beautify/src/beautifiers/tidy-markdown.coffee:11:20)
at module.exports.Beautifiers.beautify (/Users/glavin/Documents/Project Dev/atom-beautify/src/beautifiers/index.coffee:163:28)
at tryCatcher (/Users/glavin/Documents/Project Dev/atom-beautify/node_modules/bluebird/js/main/util.js:24:31)
at Promise.module.exports.Promise._resolveFromResolver (/Users/glavin/Documents/Project Dev/atom-beautify/node_modules/bluebird/js/main/promise.js:427:31)
at new Promise (/Users/glavin/Documents/Project Dev/atom-beautify/node_modules/bluebird/js/main/promise.js:53:37)
at Beautifiers.module.exports.Beautifiers.beautify (/Users/glavin/Documents/Project Dev/atom-beautify/src/beautifiers/index.coffee:100:20)
at beautify-languages-spec.coffee:155:40

/cc Glavin001/atom-beautify#292

Consider making some reformatting configurable

Since this library is a dependency of atom-tidy-markdown, but is the actual implementation of the linting, I'd like to introduce an idea of making some reformattings configurable and having those options be editable in the plugin settings page.

Namely I'd be interested in seeing empty lines between headings allowable to stay intact / allowable to collapse to a single empty line, either way, not removed at all.

Please let me know what you think about the suggestion.

Keep first and last pipe in tables

For compatibility with remark-lint (formerly mdast-lint), keep the leading and trailing (first/last) table pipes by default. Optionally, expose a function parameter to control the behavior.

tags with additional attributes are converted to markdown

moved from notslang/atom-tidy-markdown#44 by @Superbest

I noticed that <img> tags seem to be corrected too aggressively.

I have several files where I include images with something like <img src="my image.png" width=500> because the image itself is too large for a nice layout. Tidy Markdown converts these into ![](my image.png). This strips the width information, and disrupts layout.

Possible solutions (pick one:

  • Leave HTML tags alone and don't tidy them at all.
  • Don't tidy <img> tags.
  • Check the tag and only tidy if there are no properties besides src.
  • Make HTML tag tidying optional behavior.

Tables with inline LaTeX not reformatting

When I try to beautify the following code, it remains unchanged. Poorly formatted tables without LaTeX work fine.

| Diet       | Utility $(\delta = 1/2)$  | Utility $(\delta =1)$ |
 |---------- | ------- | --|
|Normal     | $U=10+(1/2) 10+(1/2)^2 10=17.5$ | $U=10+(1)10+(1)^2 10= 30$|
 |Decreasing | $U=10+(1/2) 5+(1/2)^2 20=17.5$ | $U=10+(1)5+(1)^2 20= 35$|
 |Increasing | $U=0+(1/2) 5+(1/2)^2 30=10$ | $U=0+(1)5+(1)^2 10= 35$|

strip empty <a>, <em> and <strong> tags

Not sure if there should be an option for this or if it should be automatic. We currently leave empty tags alone, in case the user is (for example) in the middle of typing out a link and then runs tidy-markdown, but maybe there should be a flag for stripping those out, especially when the user is converting from potentially messy HTML.

Can not format Chinese and Japanese

Markdown Less Pretty
a b c
中文 chinese nicely
にほんご Japanese 3
Markdown | Less     | Pretty
-------- | -------- | ----------
a        | b        | c
中文       | chinese  | **nicely**
にほんご     | Japanese | 3

a website

would be cool to have a site where users could drop in markdown, hit a button and get the output of their now tidy markdown

Nested lists add redundant new lines

I've got a nested list that looks something like

- foo
- bar
  - baz
  - fizz
- buzz
 - qux

This gets formatted into a list that looks like

- foo
- bar
  - baz
  - fizz

- buzz
 - qux

This turns what should be one list with two nested lists in it into two separate lists that contain one nested list each. This means that the list gets annoying breaks in it and doesn't read very nicely. But really, it means that anything processing a document created from this will have two separate lists instead of one which would be incorrect.

list after text doesn't work in redcarpet

The following empty line seems to be required by redcarpet and kramdown but gets removed by tidy-markdown:

Some text block with an enumeration:

- First
- Second

Without the empty line it looks like this on Github Pages:

Some text block with an enumeration: - First - Second

Make compatible with apiary's snowcrash/drafter

Currently, tidy-markdown imposes a tab length of 2 spaces (I believe), and that causes an API Blueprint file to throw a ton of warnings when run through drafter.

warn dangling message-body asset, expected a pre-formatted code block, 
indent every of it's line by 8 spaces or 2 tabs

I'm not sure if it's some expectation of their parser, or something related to this linter, but it would be amazing to have tidy-markdown (specifically, when used with atom-beautify) lint my file and have it be clean when going through the parser.

Use HTTP git remote

Hello.

I am trying to install your extension but I must use an HTTP proxy to reach the internet. However, when I try to install your extension, it tries to clone git://github.com/slang800/tidy-markdown.git, which is not possible behind a proxy.

Would it be possible to use http:// instead of git://? Most other Atom extensions do it this way and everything works fine (once I properly setup proxy configuration at my workstation).

Thanks in advance

Line removed between list and preceeding text

Originally opened as an issue for Atom Beautify

When creating a list in a markdown file, the beautifier removes the blank line between the end of the preceeding text and the beginning of the list. So what starts out like this:

Here is some sample text.

- List item
- List item

Here is some more text.

Ends up like this:

Here is some sample text.
- List item
- List item

Here is some more text.

While GitHub's markdown parser seems to be able to handle this, many others cannot and so lists end up being broken.

support html input

For people wanting to use custom compilers or just need html-to-markdown conversion. Thanks to #26, this should be easy. Something like --input=html would make sense (and just have the default be --input=markdown), but maybe a plain flag would be better.

We could also do some autodetection by reading the first chunk of text from the CLI & looking for a doctype... idk how reliable that would be.

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.