Skip to content

Commit

Permalink
Preventing issues when there are heading without text (#14)
Browse files Browse the repository at this point in the history
* Preventing issues when there are heading without text

* Changing example of github actions to cronjob
  • Loading branch information
mmiranda committed May 7, 2022
1 parent 879608e commit cdaff1a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
11 changes: 5 additions & 6 deletions .github/workflows/example.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# This is a live example of using the markdown-index in your Github Actions.
# Simply copy it to your own repo and make sure you change the working-directory
# Simply copy it to your own repo and make sure you change the working-directory
name: live-example
on:
pull_request:
push:
branches:
- main
schedule:
# Runs every monday only for example. For real example, change it to push events
- cron: '0 0 * * 1'
jobs:
markdown-index:
runs-on: ubuntu-latest
Expand All @@ -28,4 +27,4 @@ jobs:
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Automated markdown-index Documentation
file_pattern: "**/*.md"
file_pattern: "**/*.md"
5 changes: 3 additions & 2 deletions markdown/markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,9 @@ func (md *rawMarkdown) getFirstParagraph() abstractParagraph {
return s, err
} else if string(n.Text(source)) != "Table of Contents" {
rawContent := ""
// Check prevents single heading document
if doc.FirstChild() != doc.LastChild() {

// Check prevents single heading document and headings with empty text
if doc.FirstChild() != doc.LastChild() && n.NextSibling() != nil {
rawContent = string(n.NextSibling().Text(source))
}

Expand Down
2 changes: 1 addition & 1 deletion markdown/markdown_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func TestFileWithoutMetadata(t *testing.T) {

assert.False(t, file.isFileAutoGenerated())
}
func TestFileWittMetadata(t *testing.T) {
func TestFileWithMetadata(t *testing.T) {
file := newMarkdownFile(TESTDIR, TESTDIR+"/final-file-with-metadata.mock")

assert.True(t, file.isFileAutoGenerated())
Expand Down
2 changes: 2 additions & 0 deletions test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ This second paragraph must be shown only in this local README.md
# Another title

This should be completely ignored

# Title without text

0 comments on commit cdaff1a

Please sign in to comment.