forked from MapComplete/MapComplete
		
	Docs: improve docs of SpecialVisualizations.ts
This commit is contained in:
		
							parent
							
								
									e653b64e69
								
							
						
					
					
						commit
						5130a2b73a
					
				
					 6 changed files with 294 additions and 281 deletions
				
			
		|  | @ -165,7 +165,7 @@ export class GenerateDocs extends Script { | ||||||
|             this.generateForTheme(theme) |             this.generateForTheme(theme) | ||||||
|         }) |         }) | ||||||
| 
 | 
 | ||||||
|         this.WriteFile("./Docs/SpecialRenderings.md", SpecialVisualizations.HelpMessage(), [ |         this.WriteMarkdownFile("./Docs/SpecialRenderings.md", SpecialVisualizations.HelpMessage(), [ | ||||||
|             "src/UI/SpecialVisualizations.ts" |             "src/UI/SpecialVisualizations.ts" | ||||||
|         ]) |         ]) | ||||||
|         this.WriteFile( |         this.WriteFile( | ||||||
|  | @ -244,7 +244,7 @@ export class GenerateDocs extends Script { | ||||||
|         let md = markdown |         let md = markdown | ||||||
| 
 | 
 | ||||||
|         if (options?.noTableOfContents !== false) { |         if (options?.noTableOfContents !== false) { | ||||||
|             md = TableOfContents.insertTocIntoMd(md) |            md = TableOfContents.insertTocIntoMd(md) | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         md.replace(/\n\n\n+/g, "\n\n") |         md.replace(/\n\n\n+/g, "\n\n") | ||||||
|  |  | ||||||
|  | @ -143,7 +143,7 @@ export class OsmConnection { | ||||||
| 
 | 
 | ||||||
|             options.oauth_token.setData(undefined) |             options.oauth_token.setData(undefined) | ||||||
|         } |         } | ||||||
|         if (this.auth.authenticated() && options.attemptLogin !== false) { |         if (!Utils.runningFromConsole && this.auth.authenticated() && options.attemptLogin !== false) { | ||||||
|             this.AttemptLogin() |             this.AttemptLogin() | ||||||
|         } else { |         } else { | ||||||
|             console.log("Not authenticated") |             console.log("Not authenticated") | ||||||
|  |  | ||||||
|  | @ -1,11 +1,8 @@ | ||||||
| import Combine from "./Combine" |  | ||||||
| import BaseUIElement from "../BaseUIElement" | import BaseUIElement from "../BaseUIElement" | ||||||
| import Title from "./Title" |  | ||||||
| import List from "./List" | import List from "./List" | ||||||
| import Link from "./Link" |  | ||||||
| import { marked } from "marked" | import { marked } from "marked" | ||||||
| import { parse as parse_html } from "node-html-parser" | import { parse as parse_html } from "node-html-parser" | ||||||
| import {default as turndown} from "turndown" | import { default as turndown } from "turndown" | ||||||
| import { Utils } from "../../Utils" | import { Utils } from "../../Utils" | ||||||
| 
 | 
 | ||||||
| export default class TableOfContents { | export default class TableOfContents { | ||||||
|  | @ -56,7 +53,7 @@ export default class TableOfContents { | ||||||
|         const htmlSource = <string>marked.parse(md) |         const htmlSource = <string>marked.parse(md) | ||||||
|         const el = parse_html(htmlSource) |         const el = parse_html(htmlSource) | ||||||
|         const structure = TableOfContents.generateStructure(<any>el) |         const structure = TableOfContents.generateStructure(<any>el) | ||||||
|         let firstTitle = structure[1] |         const firstTitle = structure[1] | ||||||
|         let minDepth = undefined |         let minDepth = undefined | ||||||
|         do { |         do { | ||||||
|             minDepth = Math.min(...structure.map(s => s.depth)) |             minDepth = Math.min(...structure.map(s => s.depth)) | ||||||
|  | @ -81,7 +78,7 @@ export default class TableOfContents { | ||||||
|         let topLevelCount = 0 |         let topLevelCount = 0 | ||||||
|         for (const el of structure) { |         for (const el of structure) { | ||||||
|             const depthDiff = el.depth - minDepth |             const depthDiff = el.depth - minDepth | ||||||
|             let link = `[${el.title}](#${TableOfContents.asLinkableId(el.title)})` |             const link = `[${el.title}](#${TableOfContents.asLinkableId(el.title)})` | ||||||
|             if (depthDiff === 0) { |             if (depthDiff === 0) { | ||||||
|                 topLevelCount++ |                 topLevelCount++ | ||||||
|                 toc += `${topLevelCount}. ${link}\n` |                 toc += `${topLevelCount}. ${link}\n` | ||||||
|  | @ -91,16 +88,14 @@ export default class TableOfContents { | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         const heading = Utils.Times(() => "#", firstTitle.depth) |         const heading = Utils.Times(() => "#", firstTitle.depth) | ||||||
|         toc = heading +" Table of contents\n\n"+toc |         toc = heading + " Table of contents\n\n" + toc | ||||||
| 
 | 
 | ||||||
|         const original = el.outerHTML |         const firstTitleIndex = md.indexOf(firstTitle.title) | ||||||
|         const firstTitleIndex = original.indexOf(firstTitle.el.outerHTML) |  | ||||||
|         const tocHtml = (<string>marked.parse(toc)) |  | ||||||
|         const withToc = original.substring(0, firstTitleIndex) + tocHtml + original.substring(firstTitleIndex) |  | ||||||
| 
 | 
 | ||||||
|         const htmlToMd = new turndown() |         const intro = md.substring(0, firstTitleIndex) | ||||||
|         return htmlToMd.turndown(withToc) |         const splitPoint = intro.lastIndexOf("\n") | ||||||
| 
 | 
 | ||||||
|  |         return md.substring(0, splitPoint) + toc + md.substring(splitPoint) | ||||||
| 
 | 
 | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -216,7 +216,7 @@ class ApplyButton extends UIElement { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export default class AutoApplyButton implements SpecialVisualization { | export default class AutoApplyButton implements SpecialVisualization { | ||||||
|     public readonly docs: BaseUIElement |     public readonly docs: string | ||||||
|     public readonly funcName: string = "auto_apply" |     public readonly funcName: string = "auto_apply" | ||||||
|     public readonly needsUrls = [] |     public readonly needsUrls = [] | ||||||
| 
 | 
 | ||||||
|  | @ -273,7 +273,7 @@ export default class AutoApplyButton implements SpecialVisualization { | ||||||
|                 "Then, use a calculated tag on the host feature to determine the overlapping object ids", |                 "Then, use a calculated tag on the host feature to determine the overlapping object ids", | ||||||
|                 "At last, add this component", |                 "At last, add this component", | ||||||
|             ]), |             ]), | ||||||
|         ]) |         ]).AsMarkdown() | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     constr( |     constr( | ||||||
|  |  | ||||||
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							
							
								
								
									
										19
									
								
								src/Utils/MarkdownUtils.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								src/Utils/MarkdownUtils.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,19 @@ | ||||||
|  | 
 | ||||||
|  | export default class MarkdownUtils { | ||||||
|  | 
 | ||||||
|  |     public static table(header: string[], contents: string[][]){ | ||||||
|  |         let result = "" | ||||||
|  | 
 | ||||||
|  |         result += "\n\n| "+header.join(" | ") + " |\n" | ||||||
|  |         result += header.map(() => "-----").join("|") + " |\n" | ||||||
|  |         for (const line of contents) { | ||||||
|  |             if(!line){ | ||||||
|  |                 continue | ||||||
|  |             } | ||||||
|  |             result += "| " + line.map(x => x ?? "").join(" | ") + " |\n" | ||||||
|  |         } | ||||||
|  |         result += "\n\n" | ||||||
|  |         return result | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | } | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue