|  | @ -34,25 +34,30 @@ func extractFrontMatter(input string) (map[string]interface{}, string, error) { | 
			
		
	
		
		
			
				
					|  |  | 	firstLine = strings.TrimSpace(firstLine) |  |  | 	firstLine = strings.TrimSpace(firstLine) | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  | 	// see what kind of front matter there is, if any
 |  |  | 	// see what kind of front matter there is, if any
 | 
			
		
	
		
		
			
				
					
					|  |  | 	var closingFence string |  |  | 	var closingFence []string | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  | 	var fmParser func([]byte) (map[string]interface{}, error) |  |  | 	var fmParser func([]byte) (map[string]interface{}, error) | 
			
		
	
		
		
			
				
					
					|  |  | 	switch firstLine { |  |  | 	for _, fmType := range supportedFrontMatterTypes { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  | 	case yamlFrontMatterFenceOpen: |  |  | 		if firstLine == fmType.FenceOpen { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  | 		fmParser = yamlFrontMatter |  |  | 			closingFence = fmType.FenceClose | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  | 		closingFence = yamlFrontMatterFenceClose |  |  | 			fmParser = fmType.ParseFunc | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  | 	case tomlFrontMatterFenceOpen: |  |  | 		} | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  | 		fmParser = tomlFrontMatter |  |  | 	} | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  | 		closingFence = tomlFrontMatterFenceClose |  |  | 
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  | 	case jsonFrontMatterFenceOpen: |  |  | 	if fmParser == nil { | 
			
				
				
			
		
	
		
		
			
				
					|  |  | 		fmParser = jsonFrontMatter |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 		closingFence = jsonFrontMatterFenceClose |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 	default: |  |  |  | 
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					|  |  | 		// no recognized front matter; whole document is body
 |  |  | 		// no recognized front matter; whole document is body
 | 
			
		
	
		
		
			
				
					|  |  | 		return nil, input, nil |  |  | 		return nil, input, nil | 
			
		
	
		
		
			
				
					|  |  | 	} |  |  | 	} | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  | 	// find end of front matter
 |  |  | 	// find end of front matter
 | 
			
		
	
		
		
			
				
					
					|  |  | 	fmEndFenceStart := strings.Index(input[firstLineEnd:], "\n"+closingFence) |  |  | 	var fmEndFence string | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |  |  |  | 	fmEndFenceStart := -1 | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 	for _, fence := range closingFence { | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 		index := strings.Index(input[firstLineEnd:], "\n"+fence) | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 		if index >= 0 { | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 			fmEndFenceStart = index | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 			fmEndFence = fence | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 		} | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 	} | 
			
		
	
		
		
			
				
					|  |  | 	if fmEndFenceStart < 0 { |  |  | 	if fmEndFenceStart < 0 { | 
			
		
	
		
		
			
				
					|  |  | 		return nil, "", fmt.Errorf("unterminated front matter") |  |  | 		return nil, "", fmt.Errorf("unterminated front matter") | 
			
		
	
		
		
			
				
					|  |  | 	} |  |  | 	} | 
			
		
	
	
		
		
			
				
					|  | @ -66,7 +71,7 @@ func extractFrontMatter(input string) (map[string]interface{}, string, error) { | 
			
		
	
		
		
			
				
					|  |  | 	} |  |  | 	} | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  | 	// the rest is the body
 |  |  | 	// the rest is the body
 | 
			
		
	
		
		
			
				
					
					|  |  | 	body := input[fmEndFenceStart+len(closingFence):] |  |  | 	body := input[fmEndFenceStart+len(fmEndFence):] | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  | 	return fm, body, nil |  |  | 	return fm, body, nil | 
			
		
	
		
		
			
				
					|  |  | } |  |  | } | 
			
		
	
	
		
		
			
				
					|  | @ -96,8 +101,26 @@ type parsedMarkdownDoc struct { | 
			
		
	
		
		
			
				
					|  |  | 	Body string                 `json:"body,omitempty"` |  |  | 	Body string                 `json:"body,omitempty"` | 
			
		
	
		
		
			
				
					|  |  | } |  |  | } | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  | const ( |  |  | type frontMatterType struct { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  | 	yamlFrontMatterFenceOpen, yamlFrontMatterFenceClose = "---", "---" |  |  | 	FenceOpen  string | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  | 	tomlFrontMatterFenceOpen, tomlFrontMatterFenceClose = "+++", "+++" |  |  | 	FenceClose []string | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  | 	jsonFrontMatterFenceOpen, jsonFrontMatterFenceClose = "{", "}" |  |  | 	ParseFunc  func(input []byte) (map[string]interface{}, error) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  | ) |  |  | } | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  | var supportedFrontMatterTypes = []frontMatterType{ | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 	{ | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 		FenceOpen:  "---", | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 		FenceClose: []string{"---", "..."}, | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 		ParseFunc:  yamlFrontMatter, | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 	}, | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 	{ | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 		FenceOpen:  "+++", | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 		FenceClose: []string{"+++"}, | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 		ParseFunc:  tomlFrontMatter, | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 	}, | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 	{ | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 		FenceOpen:  "{", | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 		FenceClose: []string{"}"}, | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 		ParseFunc:  jsonFrontMatter, | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 	}, | 
			
		
	
		
		
			
				
					|  |  |  |  |  | } | 
			
		
	
	
		
		
			
				
					|  | 
 |