Add init support of orgmode document type on file view and readme (#2525)
* add init support of orgmode document type on file view and readme * fix imports * fix imports and readmeExist * fix imports order * fix format * remove unnecessary convert
This commit is contained in:
4
main.go
4
main.go
@ -13,6 +13,10 @@ import (
|
||||
"code.gitea.io/gitea/cmd"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
// register supported doc types
|
||||
_ "code.gitea.io/gitea/modules/markup/markdown"
|
||||
_ "code.gitea.io/gitea/modules/markup/orgmode"
|
||||
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
|
@ -13,8 +13,8 @@ import (
|
||||
"code.gitea.io/gitea/modules/base"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/mailer"
|
||||
"code.gitea.io/gitea/modules/markdown"
|
||||
"code.gitea.io/gitea/modules/markup"
|
||||
"code.gitea.io/gitea/modules/markup/markdown"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"gopkg.in/gomail.v2"
|
||||
"gopkg.in/macaron.v1"
|
||||
|
@ -10,8 +10,8 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
_ "code.gitea.io/gitea/modules/markdown"
|
||||
. "code.gitea.io/gitea/modules/markup"
|
||||
_ "code.gitea.io/gitea/modules/markup/markdown"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
@ -17,8 +17,8 @@ import (
|
||||
// Renderer is a extended version of underlying render object.
|
||||
type Renderer struct {
|
||||
blackfriday.Renderer
|
||||
urlPrefix string
|
||||
isWikiMarkdown bool
|
||||
URLPrefix string
|
||||
IsWiki bool
|
||||
}
|
||||
|
||||
// Link defines how formal links should be processed to produce corresponding HTML elements.
|
||||
@ -26,10 +26,10 @@ func (r *Renderer) Link(out *bytes.Buffer, link []byte, title []byte, content []
|
||||
if len(link) > 0 && !markup.IsLink(link) {
|
||||
if link[0] != '#' {
|
||||
lnk := string(link)
|
||||
if r.isWikiMarkdown {
|
||||
if r.IsWiki {
|
||||
lnk = markup.URLJoin("wiki", lnk)
|
||||
}
|
||||
mLink := markup.URLJoin(r.urlPrefix, lnk)
|
||||
mLink := markup.URLJoin(r.URLPrefix, lnk)
|
||||
link = []byte(mLink)
|
||||
}
|
||||
}
|
||||
@ -95,8 +95,8 @@ var (
|
||||
|
||||
// Image defines how images should be processed to produce corresponding HTML elements.
|
||||
func (r *Renderer) Image(out *bytes.Buffer, link []byte, title []byte, alt []byte) {
|
||||
prefix := r.urlPrefix
|
||||
if r.isWikiMarkdown {
|
||||
prefix := r.URLPrefix
|
||||
if r.IsWiki {
|
||||
prefix = markup.URLJoin(prefix, "wiki", "src")
|
||||
}
|
||||
prefix = strings.Replace(prefix, "/src/", "/raw/", 1)
|
||||
@ -129,9 +129,9 @@ func RenderRaw(body []byte, urlPrefix string, wikiMarkdown bool) []byte {
|
||||
htmlFlags |= blackfriday.HTML_SKIP_STYLE
|
||||
htmlFlags |= blackfriday.HTML_OMIT_CONTENTS
|
||||
renderer := &Renderer{
|
||||
Renderer: blackfriday.HtmlRenderer(htmlFlags, "", ""),
|
||||
urlPrefix: urlPrefix,
|
||||
isWikiMarkdown: wikiMarkdown,
|
||||
Renderer: blackfriday.HtmlRenderer(htmlFlags, "", ""),
|
||||
URLPrefix: urlPrefix,
|
||||
IsWiki: wikiMarkdown,
|
||||
}
|
||||
|
||||
// set up the parser
|
@ -5,13 +5,11 @@
|
||||
package markdown_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
. "code.gitea.io/gitea/modules/markdown"
|
||||
"code.gitea.io/gitea/modules/markup"
|
||||
. "code.gitea.io/gitea/modules/markup/markdown"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@ -21,45 +19,6 @@ const AppURL = "http://localhost:3000/"
|
||||
const Repo = "gogits/gogs"
|
||||
const AppSubURL = AppURL + Repo + "/"
|
||||
|
||||
var numericMetas = map[string]string{
|
||||
"format": "https://someurl.com/{user}/{repo}/{index}",
|
||||
"user": "someUser",
|
||||
"repo": "someRepo",
|
||||
"style": markup.IssueNameStyleNumeric,
|
||||
}
|
||||
|
||||
var alphanumericMetas = map[string]string{
|
||||
"format": "https://someurl.com/{user}/{repo}/{index}",
|
||||
"user": "someUser",
|
||||
"repo": "someRepo",
|
||||
"style": markup.IssueNameStyleAlphanumeric,
|
||||
}
|
||||
|
||||
// numericLink an HTML to a numeric-style issue
|
||||
func numericIssueLink(baseURL string, index int) string {
|
||||
return link(markup.URLJoin(baseURL, strconv.Itoa(index)), fmt.Sprintf("#%d", index))
|
||||
}
|
||||
|
||||
// alphanumLink an HTML link to an alphanumeric-style issue
|
||||
func alphanumIssueLink(baseURL string, name string) string {
|
||||
return link(markup.URLJoin(baseURL, name), name)
|
||||
}
|
||||
|
||||
// urlContentsLink an HTML link whose contents is the target URL
|
||||
func urlContentsLink(href string) string {
|
||||
return link(href, href)
|
||||
}
|
||||
|
||||
// link an HTML link
|
||||
func link(href, contents string) string {
|
||||
return fmt.Sprintf("<a href=\"%s\">%s</a>", href, contents)
|
||||
}
|
||||
|
||||
func testRenderIssueIndexPattern(t *testing.T, input, expected string, metas map[string]string) {
|
||||
assert.Equal(t, expected,
|
||||
string(markup.RenderIssueIndexPattern([]byte(input), AppSubURL, metas)))
|
||||
}
|
||||
|
||||
func TestRender_StandardLinks(t *testing.T) {
|
||||
setting.AppURL = AppURL
|
||||
setting.AppSubURL = AppSubURL
|
@ -7,8 +7,8 @@ package markup_test
|
||||
import (
|
||||
"testing"
|
||||
|
||||
_ "code.gitea.io/gitea/modules/markdown"
|
||||
. "code.gitea.io/gitea/modules/markup"
|
||||
_ "code.gitea.io/gitea/modules/markup/markdown"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
56
modules/markup/orgmode/orgmode.go
Normal file
56
modules/markup/orgmode/orgmode.go
Normal file
@ -0,0 +1,56 @@
|
||||
// Copyright 2017 The Gitea Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package markup
|
||||
|
||||
import (
|
||||
"code.gitea.io/gitea/modules/markup"
|
||||
"code.gitea.io/gitea/modules/markup/markdown"
|
||||
|
||||
"github.com/chaseadamsio/goorgeous"
|
||||
"github.com/russross/blackfriday"
|
||||
)
|
||||
|
||||
func init() {
|
||||
markup.RegisterParser(Parser{})
|
||||
}
|
||||
|
||||
// Parser implements markup.Parser for orgmode
|
||||
type Parser struct {
|
||||
}
|
||||
|
||||
// Name implements markup.Parser
|
||||
func (Parser) Name() string {
|
||||
return "orgmode"
|
||||
}
|
||||
|
||||
// Extensions implements markup.Parser
|
||||
func (Parser) Extensions() []string {
|
||||
return []string{".org"}
|
||||
}
|
||||
|
||||
// Render renders orgmode rawbytes to HTML
|
||||
func Render(rawBytes []byte, urlPrefix string, metas map[string]string, isWiki bool) []byte {
|
||||
htmlFlags := blackfriday.HTML_USE_XHTML
|
||||
htmlFlags |= blackfriday.HTML_SKIP_STYLE
|
||||
htmlFlags |= blackfriday.HTML_OMIT_CONTENTS
|
||||
renderer := &markdown.Renderer{
|
||||
Renderer: blackfriday.HtmlRenderer(htmlFlags, "", ""),
|
||||
URLPrefix: urlPrefix,
|
||||
IsWiki: isWiki,
|
||||
}
|
||||
|
||||
result := goorgeous.Org(rawBytes, renderer)
|
||||
return result
|
||||
}
|
||||
|
||||
// RenderString reners orgmode string to HTML string
|
||||
func RenderString(rawContent string, urlPrefix string, metas map[string]string, isWiki bool) string {
|
||||
return string(Render([]byte(rawContent), urlPrefix, metas, isWiki))
|
||||
}
|
||||
|
||||
// Render implements markup.Parser
|
||||
func (Parser) Render(rawBytes []byte, urlPrefix string, metas map[string]string, isWiki bool) []byte {
|
||||
return Render(rawBytes, urlPrefix, metas, isWiki)
|
||||
}
|
54
modules/markup/orgmode/orgmode_test.go
Normal file
54
modules/markup/orgmode/orgmode_test.go
Normal file
@ -0,0 +1,54 @@
|
||||
// Copyright 2017 The Gitea Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package markup
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/modules/markup"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
const AppURL = "http://localhost:3000/"
|
||||
const Repo = "gogits/gogs"
|
||||
const AppSubURL = AppURL + Repo + "/"
|
||||
|
||||
func TestRender_StandardLinks(t *testing.T) {
|
||||
setting.AppURL = AppURL
|
||||
setting.AppSubURL = AppSubURL
|
||||
|
||||
test := func(input, expected string) {
|
||||
buffer := RenderString(input, setting.AppSubURL, nil, false)
|
||||
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer))
|
||||
}
|
||||
|
||||
googleRendered := `<p><a href="https://google.com/" title="https://google.com/">https://google.com/</a></p>`
|
||||
test("[[https://google.com/]]", googleRendered)
|
||||
|
||||
lnk := markup.URLJoin(AppSubURL, "WikiPage")
|
||||
test("[[WikiPage][WikiPage]]",
|
||||
`<p><a href="`+lnk+`" title="WikiPage">WikiPage</a></p>`)
|
||||
}
|
||||
|
||||
func TestRender_Images(t *testing.T) {
|
||||
setting.AppURL = AppURL
|
||||
setting.AppSubURL = AppSubURL
|
||||
|
||||
test := func(input, expected string) {
|
||||
buffer := RenderString(input, setting.AppSubURL, nil, false)
|
||||
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer))
|
||||
}
|
||||
|
||||
url := "../../.images/src/02/train.jpg"
|
||||
title := "Train"
|
||||
result := markup.URLJoin(AppSubURL, url)
|
||||
|
||||
test(
|
||||
"[[file:"+url+"]["+title+"]]",
|
||||
`<p><a href="`+result+`"><img src="`+result+`" alt="`+title+`" title="`+title+`" /></a></p>`)
|
||||
}
|
@ -8,8 +8,8 @@ import (
|
||||
api "code.gitea.io/sdk/gitea"
|
||||
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/markdown"
|
||||
"code.gitea.io/gitea/modules/markup"
|
||||
"code.gitea.io/gitea/modules/markup/markdown"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
)
|
||||
|
||||
|
@ -24,7 +24,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/indexer"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/markdown"
|
||||
"code.gitea.io/gitea/modules/markup/markdown"
|
||||
"code.gitea.io/gitea/modules/notification"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/base"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/markdown"
|
||||
"code.gitea.io/gitea/modules/markup/markdown"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
||||
"github.com/Unknwon/paginater"
|
||||
|
@ -95,11 +95,11 @@ func renderDirectory(ctx *context.Context, treeLink string) {
|
||||
buf = append(buf, d...)
|
||||
newbuf := markup.Render(readmeFile.Name(), buf, treeLink, ctx.Repo.Repository.ComposeMetas())
|
||||
if newbuf != nil {
|
||||
ctx.Data["IsMarkdown"] = true
|
||||
ctx.Data["IsMarkup"] = true
|
||||
} else {
|
||||
// FIXME This is the only way to show non-markdown files
|
||||
// instead of a broken "View Raw" link
|
||||
ctx.Data["IsMarkdown"] = true
|
||||
ctx.Data["IsMarkup"] = false
|
||||
newbuf = bytes.Replace(buf, []byte("\n"), []byte(`<br>`), -1)
|
||||
}
|
||||
ctx.Data["FileContent"] = string(newbuf)
|
||||
@ -197,10 +197,8 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
|
||||
|
||||
tp := markup.Type(blob.Name())
|
||||
isSupportedMarkup := tp != ""
|
||||
// FIXME: currently set IsMarkdown for compatible
|
||||
ctx.Data["IsMarkdown"] = isSupportedMarkup
|
||||
|
||||
readmeExist := isSupportedMarkup || markup.IsReadmeFile(blob.Name())
|
||||
ctx.Data["IsMarkup"] = isSupportedMarkup
|
||||
readmeExist := markup.IsReadmeFile(blob.Name())
|
||||
ctx.Data["ReadmeExist"] = readmeExist
|
||||
if readmeExist && isSupportedMarkup {
|
||||
ctx.Data["FileContent"] = string(markup.Render(blob.Name(), buf, path.Dir(treeLink), ctx.Repo.Repository.ComposeMetas()))
|
||||
|
@ -18,8 +18,8 @@ import (
|
||||
"code.gitea.io/gitea/modules/auth"
|
||||
"code.gitea.io/gitea/modules/base"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/markdown"
|
||||
"code.gitea.io/gitea/modules/markup"
|
||||
"code.gitea.io/gitea/modules/markup/markdown"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -36,8 +36,8 @@
|
||||
{{end}}
|
||||
</h4>
|
||||
<div class="ui attached table segment">
|
||||
<div class="file-view {{if .IsMarkdown}}markdown{{else if .IsTextFile}}code-view{{end}} has-emoji">
|
||||
{{if .IsMarkdown}}
|
||||
<div class="file-view {{if .IsMarkup}}markdown{{else if .IsTextFile}}code-view{{end}} has-emoji">
|
||||
{{if .IsMarkup}}
|
||||
{{if .FileContent}}{{.FileContent | Str2html}}{{end}}
|
||||
{{else if not .IsTextFile}}
|
||||
<div class="view-raw ui center">
|
||||
|
21
vendor/github.com/chaseadamsio/goorgeous/LICENSE
generated
vendored
Normal file
21
vendor/github.com/chaseadamsio/goorgeous/LICENSE
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2017 Chase Adams <realchaseadams@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
66
vendor/github.com/chaseadamsio/goorgeous/README.org
generated
vendored
Normal file
66
vendor/github.com/chaseadamsio/goorgeous/README.org
generated
vendored
Normal file
@ -0,0 +1,66 @@
|
||||
#+TITLE: chaseadamsio/goorgeous
|
||||
|
||||
[[https://travis-ci.org/chaseadamsio/goorgeous.svg?branch=master]]
|
||||
[[https://coveralls.io/repos/github/chaseadamsio/goorgeous/badge.svg?branch=master]]
|
||||
|
||||
/goorgeous is a Go Org to HTML Parser./
|
||||
|
||||
[[file:gopher_small.gif]]
|
||||
|
||||
*Pronounced: Go? Org? Yes!*
|
||||
|
||||
#+BEGIN_QUOTE
|
||||
"Org mode is for keeping notes, maintaining TODO lists, planning projects, and authoring documents with a fast and effective plain-text system."
|
||||
|
||||
- [[orgmode.org]]
|
||||
#+END_QUOTE
|
||||
|
||||
The purpose of this package is to come as close as possible as parsing an =*.org= document into HTML, the same way one might publish [[http://orgmode.org/worg/org-tutorials/org-publish-html-tutorial.html][with org-publish-html from Emacs]].
|
||||
|
||||
* Installation
|
||||
|
||||
#+BEGIN_SRC sh
|
||||
go get -u github.com/chaseadamsio/goorgeous
|
||||
#+END_SRC
|
||||
|
||||
* Usage
|
||||
|
||||
** Org Headers
|
||||
|
||||
To retrieve the headers from a =[]byte=, call =OrgHeaders= and it will return a =map[string]interface{}=:
|
||||
|
||||
#+BEGIN_SRC go
|
||||
input := "#+title: goorgeous\n* Some Headline\n"
|
||||
out := goorgeous.OrgHeaders(input)
|
||||
#+END_SRC
|
||||
|
||||
#+BEGIN_SRC go
|
||||
map[string]interface{}{
|
||||
"title": "goorgeous"
|
||||
}
|
||||
#+END_SRC
|
||||
|
||||
** Org Content
|
||||
|
||||
After importing =github.com/chaseadamsio/goorgeous=, you can call =Org= with a =[]byte= and it will return an =html= version of the content as a =[]byte=
|
||||
|
||||
#+BEGIN_SRC go
|
||||
input := "#+TITLE: goorgeous\n* Some Headline\n"
|
||||
out := goorgeous.Org(input)
|
||||
#+END_SRC
|
||||
|
||||
=out= will be:
|
||||
|
||||
#+BEGIN_SRC html
|
||||
<h1>Some Headline</h1>/n
|
||||
#+END_SRC
|
||||
|
||||
* Why?
|
||||
|
||||
First off, I've become an unapologetic user of Emacs & ever since finding =org-mode= I use it for anything having to do with writing content, organizing my life and keeping documentation of my days/weeks/months.
|
||||
|
||||
Although I like Emacs & =emacs-lisp=, I publish all of my html sites with [[https://gohugo.io][Hugo Static Site Generator]] and wanted to be able to write my content in =org-mode= in Emacs rather than markdown.
|
||||
|
||||
Hugo's implementation of templating and speed are unmatched, so the only way I knew for sure I could continue to use Hugo and write in =org-mode= seamlessly was to write a golang parser for org content and submit a PR for Hugo to use it.
|
||||
* Acknowledgements
|
||||
I leaned heavily on russross' [[https://github.com/russross/blackfriday][blackfriday markdown renderer]] as both an example of how to write a parser (with some updates to leverage the go we know today) and reusing the blackfriday HTML Renderer so I didn't have to write my own!
|
803
vendor/github.com/chaseadamsio/goorgeous/goorgeous.go
generated
vendored
Normal file
803
vendor/github.com/chaseadamsio/goorgeous/goorgeous.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
BIN
vendor/github.com/chaseadamsio/goorgeous/gopher.gif
generated
vendored
Normal file
BIN
vendor/github.com/chaseadamsio/goorgeous/gopher.gif
generated
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 15 KiB |
BIN
vendor/github.com/chaseadamsio/goorgeous/gopher_small.gif
generated
vendored
Normal file
BIN
vendor/github.com/chaseadamsio/goorgeous/gopher_small.gif
generated
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.2 KiB |
70
vendor/github.com/chaseadamsio/goorgeous/header.go
generated
vendored
Normal file
70
vendor/github.com/chaseadamsio/goorgeous/header.go
generated
vendored
Normal file
@ -0,0 +1,70 @@
|
||||
package goorgeous
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// ExtractOrgHeaders finds and returns all of the headers
|
||||
// from a bufio.Reader and returns them as their own byte slice
|
||||
func ExtractOrgHeaders(r *bufio.Reader) (fm []byte, err error) {
|
||||
var out bytes.Buffer
|
||||
endOfHeaders := true
|
||||
for endOfHeaders {
|
||||
p, err := r.Peek(2)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !charMatches(p[0], '#') && !charMatches(p[1], '+') {
|
||||
endOfHeaders = false
|
||||
break
|
||||
}
|
||||
line, _, err := r.ReadLine()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out.Write(line)
|
||||
out.WriteByte('\n')
|
||||
}
|
||||
return out.Bytes(), nil
|
||||
}
|
||||
|
||||
var reHeader = regexp.MustCompile(`^#\+(\w+?): (.*)`)
|
||||
|
||||
// OrgHeaders find all of the headers from a byte slice and returns
|
||||
// them as a map of string interface
|
||||
func OrgHeaders(input []byte) (map[string]interface{}, error) {
|
||||
out := make(map[string]interface{})
|
||||
scanner := bufio.NewScanner(bytes.NewReader(input))
|
||||
|
||||
for scanner.Scan() {
|
||||
data := scanner.Bytes()
|
||||
if !charMatches(data[0], '#') && !charMatches(data[1], '+') {
|
||||
return out, nil
|
||||
}
|
||||
matches := reHeader.FindSubmatch(data)
|
||||
|
||||
if len(matches) < 3 {
|
||||
continue
|
||||
}
|
||||
|
||||
key := string(matches[1])
|
||||
val := matches[2]
|
||||
switch {
|
||||
case strings.ToLower(key) == "tags" || strings.ToLower(key) == "categories" || strings.ToLower(key) == "aliases":
|
||||
bTags := bytes.Split(val, []byte(" "))
|
||||
tags := make([]string, len(bTags))
|
||||
for idx, tag := range bTags {
|
||||
tags[idx] = string(tag)
|
||||
}
|
||||
out[key] = tags
|
||||
default:
|
||||
out[key] = string(val)
|
||||
}
|
||||
|
||||
}
|
||||
return out, nil
|
||||
|
||||
}
|
6
vendor/vendor.json
vendored
6
vendor/vendor.json
vendored
@ -299,6 +299,12 @@
|
||||
"revision": "fb1f79c6b65acda83063cbc69f6bba1522558bfc",
|
||||
"revisionTime": "2016-01-17T19:21:50Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "x1svIugw39oEZGU5/HMUHzgRUZM=",
|
||||
"path": "github.com/chaseadamsio/goorgeous",
|
||||
"revision": "098da33fde5f9220736531b3cb26a2dec86a8367",
|
||||
"revisionTime": "2017-09-01T13:22:37Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "agNqSytP0indDCoGizlMyC1L/m4=",
|
||||
"path": "github.com/coreos/etcd/error",
|
||||
|
Reference in New Issue
Block a user