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.WriteFile("./Docs/SpecialRenderings.md", SpecialVisualizations.HelpMessage(), [ | ||||
|         this.WriteMarkdownFile("./Docs/SpecialRenderings.md", SpecialVisualizations.HelpMessage(), [ | ||||
|             "src/UI/SpecialVisualizations.ts" | ||||
|         ]) | ||||
|         this.WriteFile( | ||||
|  | @ -244,7 +244,7 @@ export class GenerateDocs extends Script { | |||
|         let md = markdown | ||||
| 
 | ||||
|         if (options?.noTableOfContents !== false) { | ||||
|             md = TableOfContents.insertTocIntoMd(md) | ||||
|            md = TableOfContents.insertTocIntoMd(md) | ||||
|         } | ||||
| 
 | ||||
|         md.replace(/\n\n\n+/g, "\n\n") | ||||
|  |  | |||
|  | @ -143,7 +143,7 @@ export class OsmConnection { | |||
| 
 | ||||
|             options.oauth_token.setData(undefined) | ||||
|         } | ||||
|         if (this.auth.authenticated() && options.attemptLogin !== false) { | ||||
|         if (!Utils.runningFromConsole && this.auth.authenticated() && options.attemptLogin !== false) { | ||||
|             this.AttemptLogin() | ||||
|         } else { | ||||
|             console.log("Not authenticated") | ||||
|  |  | |||
|  | @ -1,11 +1,8 @@ | |||
| import Combine from "./Combine" | ||||
| import BaseUIElement from "../BaseUIElement" | ||||
| import Title from "./Title" | ||||
| import List from "./List" | ||||
| import Link from "./Link" | ||||
| import { marked } from "marked" | ||||
| 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" | ||||
| 
 | ||||
| export default class TableOfContents { | ||||
|  | @ -56,7 +53,7 @@ export default class TableOfContents { | |||
|         const htmlSource = <string>marked.parse(md) | ||||
|         const el = parse_html(htmlSource) | ||||
|         const structure = TableOfContents.generateStructure(<any>el) | ||||
|         let firstTitle = structure[1] | ||||
|         const firstTitle = structure[1] | ||||
|         let minDepth = undefined | ||||
|         do { | ||||
|             minDepth = Math.min(...structure.map(s => s.depth)) | ||||
|  | @ -81,7 +78,7 @@ export default class TableOfContents { | |||
|         let topLevelCount = 0 | ||||
|         for (const el of structure) { | ||||
|             const depthDiff = el.depth - minDepth | ||||
|             let link = `[${el.title}](#${TableOfContents.asLinkableId(el.title)})` | ||||
|             const link = `[${el.title}](#${TableOfContents.asLinkableId(el.title)})` | ||||
|             if (depthDiff === 0) { | ||||
|                 topLevelCount++ | ||||
|                 toc += `${topLevelCount}. ${link}\n` | ||||
|  | @ -91,16 +88,14 @@ export default class TableOfContents { | |||
|         } | ||||
| 
 | ||||
|         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 = original.indexOf(firstTitle.el.outerHTML) | ||||
|         const tocHtml = (<string>marked.parse(toc)) | ||||
|         const withToc = original.substring(0, firstTitleIndex) + tocHtml + original.substring(firstTitleIndex) | ||||
|         const firstTitleIndex = md.indexOf(firstTitle.title) | ||||
| 
 | ||||
|         const htmlToMd = new turndown() | ||||
|         return htmlToMd.turndown(withToc) | ||||
|         const intro = md.substring(0, firstTitleIndex) | ||||
|         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 { | ||||
|     public readonly docs: BaseUIElement | ||||
|     public readonly docs: string | ||||
|     public readonly funcName: string = "auto_apply" | ||||
|     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", | ||||
|                 "At last, add this component", | ||||
|             ]), | ||||
|         ]) | ||||
|         ]).AsMarkdown() | ||||
|     } | ||||
| 
 | ||||
|     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