Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use hash headers only. #13

Merged
merged 1 commit into from
Oct 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
markdownfmt
===========

Fork of github.com/shurcooL/markdownfmt that targets goldmark to render from parsed markdown AST.
Fork of github.com/shurcooL/markdownfmt that targets:

* Goldmark to render from parsed markdown AST.
* Hash-based headers only.



[![Build Status](https://travis-ci.org/Kunde21/markdownfmt.svg?branch=master)](https://travis-ci.org/Kunde21/markdownfmt) [![GoDoc](https://godoc.org/github.com/Kunde21/markdownfmt?status.svg)](https://godoc.org/github.com/Kunde21/markdownfmt)

Expand Down
20 changes: 2 additions & 18 deletions markdown/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,8 @@ func (_ *MarkdownFmtRenderer) stringWidth(s string) int {
func (mr *MarkdownFmtRenderer) header(node *ast.Heading, text []byte) {
mr.spaceBeforeParagraph(node)

if node.Level >= 3 {
mr.buf.Write(bytes.Repeat([]byte{'#'}, node.Level))
mr.buf.WriteByte(' ')
}
mr.buf.Write(bytes.Repeat([]byte{'#'}, node.Level))
mr.buf.WriteByte(' ')

newBuf := bytes.NewBuffer(nil)

Expand All @@ -172,21 +170,7 @@ func (mr *MarkdownFmtRenderer) header(node *ast.Heading, text []byte) {
fmt.Fprintf(newBuf, " {#%s}", id)
}

slen := mr.stringWidth(newBuf.String())

mr.buf.Write(newBuf.Bytes())

switch node.Level {
case 1:
mr.buf.WriteByte('\n')
mr.buf.Write(mr.leader())
mr.buf.Write(bytes.Repeat([]byte{'='}, slen))
case 2:
mr.buf.WriteByte('\n')
mr.buf.Write(mr.leader())
mr.buf.Write(bytes.Repeat([]byte{'-'}, slen))
}

mr.buf.WriteString("\n")
}

Expand Down
9 changes: 3 additions & 6 deletions markdown/testfiles/example1.output.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Title
=====
# Title

This is a new paragraph. I wonder if I have too many spaces. What about new paragraph. But the next one...

Expand All @@ -8,11 +7,9 @@ Is really new.
1. Item one.
2. Item TWO.

Title
=====
# Title

Subtitle
--------
## Subtitle

How about `this` and other stuff like *italic*, *underline italic*, **bold**, **bold spaces**.

Expand Down
39 changes: 13 additions & 26 deletions markdown/testfiles/headers.same.md
Original file line number Diff line number Diff line change
@@ -1,52 +1,39 @@
Header
======
# Header

Hea *de* r
==========
# Hea *de* r

Hea `de` r
==========
# Hea `de` r

Header
------
## Header

text

Header
======
# Header

Header
------
## Header

### Header

text

Header
======
# Header

Header
======
# Header

Header {#custom}
================
# Header {#custom}

### Header {#custom}

> quote
>
> Header
> ======
> # Header
>
> Header
> ------
> ## Header

Paragraph

> Header
> ======
> # Header
>
> Header {#custom}
> ----------------
> ## Header {#custom}
>
> ### Header {#custom}
12 changes: 4 additions & 8 deletions markdown/testfiles/reference.same.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
An h1 header
============
# An h1 header

Paragraphs are separated by a blank line.

Expand All @@ -24,8 +23,7 @@ Trying items.

Last paragraph here.

An h2 header
------------
## An h2 header

- Paragraph right away.
- **Big item**: Right away after header.
Expand Down Expand Up @@ -101,8 +99,7 @@ The outer pipes (|) are optional, and you don't need to make the raw Markdown li
| *Still* | `renders` | **nicely** |
| 1 | 2 | 3 |

Nested Lists
============
# Nested Lists

### Codeblock within list

Expand Down Expand Up @@ -147,8 +144,7 @@ Para

- Item 3

Line Breaks
===========
# Line Breaks

Some text with two trailing spaces for linebreak.
More text immediately after.
Expand Down
6 changes: 2 additions & 4 deletions markdown/testfiles/things-inside-blocks.same.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,11 @@ List can have things inside
>
> > why not

6. Header
======
6. # Header

7. Text can have

Header
======
# Header

or

Expand Down
9 changes: 3 additions & 6 deletions markdown/testfiles/widechar.output.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
タイトル
========
# タイトル

サブタイトル
------------
## サブタイトル

aaa/あああ
----------
## aaa/あああ

s