mirror of
				https://github.com/kovetskiy/mark.git
				synced 2025-10-31 03:37:35 +08:00 
			
		
		
		
	Merge pull request #5 from seletskiy/new-headers
Add parser for new-style headers
This commit is contained in:
		
						commit
						eb30d1d1fc
					
				| @ -22,10 +22,10 @@ Confluence instance and update it accordingly. | |||||||
| 
 | 
 | ||||||
| File in extended format should follow specification | File in extended format should follow specification | ||||||
| ```markdown | ```markdown | ||||||
| []:# (X-Space: <space key>) | <!-- Space: <space key> --> | ||||||
| []:# (X-Parent: <parent 1>) | <!-- Parent: <parent 1> --> | ||||||
| []:# (X-Parent: <parent 2>) | <!-- Parent: <parent 2> --> | ||||||
| []:# (X-Title: <title>) | <!-- Title: <title> --> | ||||||
| 
 | 
 | ||||||
| <page contents> | <page contents> | ||||||
| ``` | ``` | ||||||
|  | |||||||
| @ -25,7 +25,7 @@ const ( | |||||||
| 
 | 
 | ||||||
| type Restriction struct { | type Restriction struct { | ||||||
| 	User  string `json:"userName"` | 	User  string `json:"userName"` | ||||||
| 	Group string `json:"groupName",omitempty` | 	Group string `json:"groupName,omitempty"` | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type API struct { | type API struct { | ||||||
|  | |||||||
| @ -43,7 +43,10 @@ type Meta struct { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func ExtractMeta(data []byte) (*Meta, error) { | func ExtractMeta(data []byte) (*Meta, error) { | ||||||
| 	headerPattern := regexp.MustCompile(`\[\]:\s*#\s*\(([^:]+):\s*(.*)\)`) | 	var ( | ||||||
|  | 		headerPatternV1 = regexp.MustCompile(`\[\]:\s*#\s*\(([^:]+):\s*(.*)\)`) | ||||||
|  | 		headerPatternV2 = regexp.MustCompile(`<!--\s*([^:]+):\s*(.*)\s*-->`) | ||||||
|  | 	) | ||||||
| 
 | 
 | ||||||
| 	var meta *Meta | 	var meta *Meta | ||||||
| 
 | 
 | ||||||
| @ -55,9 +58,19 @@ func ExtractMeta(data []byte) (*Meta, error) { | |||||||
| 			return nil, err | 			return nil, err | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		matches := headerPattern.FindStringSubmatch(line) | 		matches := headerPatternV2.FindStringSubmatch(line) | ||||||
| 		if matches == nil { | 		if matches == nil { | ||||||
| 			break | 			matches = headerPatternV1.FindStringSubmatch(line) | ||||||
|  | 			if matches == nil { | ||||||
|  | 				break | ||||||
|  | 			} | ||||||
|  | 
 | ||||||
|  | 			log.Warningf( | ||||||
|  | 				fmt.Errorf(`legacy header usage found: %s`, line), | ||||||
|  | 				"please use new header format: <!-- %s: %s -->", | ||||||
|  | 				matches[1], | ||||||
|  | 				matches[2], | ||||||
|  | 			) | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		if meta == nil { | 		if meta == nil { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Egor Kovetskiy
						Egor Kovetskiy