Skip to content

Commit

Permalink
Merge pull request #15 from schoero/development
Browse files Browse the repository at this point in the history
chore(release): v0.2.5
  • Loading branch information
schoero authored Nov 11, 2023
2 parents 457cf0b + 0786f77 commit d4ebf83
Show file tree
Hide file tree
Showing 25 changed files with 258 additions and 135 deletions.
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
# Changelog

## v0.2.5

[compare changes](https://github.com/schoero/unwritten/compare/v0.2.3...v0.2.5)

### Fixes

- Render class name instead of `class` ([428d443](https://github.com/schoero/unwritten/commit/428d443))
- Rendering violation in user provided markdown ([6d562c0](https://github.com/schoero/unwritten/commit/6d562c0))

### Refactors

- Update logo ([9529487](https://github.com/schoero/unwritten/commit/9529487))
- Update logo ([f076b20](https://github.com/schoero/unwritten/commit/f076b20))

### Chore

- Remove unused types ([5a78055](https://github.com/schoero/unwritten/commit/5a78055))
- **release:** V0.2.4 ([3b4e32a](https://github.com/schoero/unwritten/commit/3b4e32a))

### Styles

- Code cleanup ([f0d7b8a](https://github.com/schoero/unwritten/commit/f0d7b8a))

### ❤️ Contributors

- Roger Schönbächler

## v0.2.4

[compare changes](https://github.com/schoero/unwritten/compare/v0.2.2...v0.2.4)
Expand Down
20 changes: 10 additions & 10 deletions assets/unwritten-dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 10 additions & 10 deletions assets/unwritten-light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 10 additions & 10 deletions assets/unwritten.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.2.4",
"version": "0.2.5",
"type": "module",
"name": "unwritten",
"description": "unwritten is a cli tool that auto generates documentation from your JavaScript or TypeScript project by utilizing TSDoc or JSDoc comments.",
Expand Down
3 changes: 1 addition & 2 deletions src/compiler/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ export function compile(ctx: DefaultContext, code: string, tsconfig?: CompilerOp
const checker = program.getTypeChecker();


//-- Report any compiler messages

// Report any compiler messages
void reportCompilerDiagnostics(ctx, program.getSemanticDiagnostics());

return { checker, program };
Expand Down
6 changes: 2 additions & 4 deletions src/compiler/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ export function compile(ctx: DefaultContext, entryFilePaths: string[], tsConfigO
: tsConfigOrFilePath;


//-- Compile

// Compile
const compilerOptions = getCompilerOptions(ctx, absoluteEntryFilePaths, tsConfigOrResolvedFilePath);
const compilerHost = getCompilerHost(ctx, compilerOptions);

Expand All @@ -35,8 +34,7 @@ export function compile(ctx: DefaultContext, entryFilePaths: string[], tsConfigO
const checker = program.getTypeChecker();


//-- Report any compiler messages

// Report any compiler messages
void reportCompilerDiagnostics(ctx, program.getSemanticDiagnostics());

return { checker, program };
Expand Down
4 changes: 1 addition & 3 deletions src/renderer/markup/ast-converter/shared/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ export function convertExamplesForType(ctx: MarkupRenderContexts, examples: Exam
return createInlineTitleNode(
title,
anchor,
createParagraphNode(
...convertedExamples
)
...convertedExamples
);

}
3 changes: 0 additions & 3 deletions src/renderer/markup/enums/renderer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//-- Categories


export enum RenderCategories {
Class = "class",
Classes = "classes",
Expand Down
14 changes: 7 additions & 7 deletions src/renderer/markup/html/ast/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
isParagraphNode,
isTitleNode
} from "unwritten:renderer:markup/typeguards/renderer";
import { renderIndentation } from "unwritten:renderer:utils/indentation";
import { renderWithIndentation } from "unwritten:renderer:utils/indentation";

import { renderNode } from "../index";

Expand Down Expand Up @@ -55,12 +55,12 @@ function renderListItems(ctx: HTMLRenderContext, items: ASTNode[]): string[] {
}

function renderListStart(ctx: HTMLRenderContext): string {
const renderedListStart = `${renderIndentation(ctx)}<ul>`;
const renderedListStart = renderWithIndentation(ctx, "<ul>");
return renderedListStart;
}

function renderListItemStart(ctx: HTMLRenderContext): string {
const renderedListStart = `${renderIndentation(ctx)}<li>`;
const renderedListStart = renderWithIndentation(ctx, "<li>");
return renderedListStart;
}

Expand All @@ -81,7 +81,7 @@ function renderListItem(ctx: HTMLRenderContext, item: ASTNode): string {
return "";
}

return `${renderIndentation(ctx)}${renderedArrayItems}`;
return renderWithIndentation(ctx, renderedArrayItems);

}, item);

Expand Down Expand Up @@ -128,16 +128,16 @@ function renderListItem(ctx: HTMLRenderContext, item: ASTNode): string {

return renderedItem === ""
? renderedItem
: `${renderIndentation(ctx)}<li>${renderedItem}</li>`;
: renderWithIndentation(ctx, `<li>${renderedItem}</li>`);

}

function renderListEnd(ctx: HTMLRenderContext): string {
return `${renderIndentation(ctx)}</ul>`;
return renderWithIndentation(ctx, "</ul>");
}

function renderListItemEnd(ctx: HTMLRenderContext): string {
return `${renderIndentation(ctx)}</li>`;
return renderWithIndentation(ctx, "</li>");
}

function flattenNestedArrayItems(items: ASTNode[]): ASTNode[] {
Expand Down
19 changes: 3 additions & 16 deletions src/renderer/markup/html/ast/multiline.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { renderIndentation } from "unwritten:renderer/utils/indentation";
import { renderWithIndentation } from "unwritten:renderer/utils/indentation";
import { renderNewLine } from "unwritten:renderer/utils/new-line";
import { renderNode } from "unwritten:renderer:html/index";

Expand All @@ -9,23 +9,10 @@ import type { MultilineNode } from "unwritten:renderer:markup/types-definitions/
export function renderMultilineNode(ctx: HTMLRenderContext, multilineNode: MultilineNode): string {

const renderedNewLine = renderNewLine(ctx);
const renderedIndentation = renderIndentation(ctx);

return multilineNode.children.map((subNode, index) => {

const renderedNode = renderNode(ctx, subNode);

if(renderedNode === ""){
return "";
}

// Render indentation for all children
const renderedNodeWithIndentation = renderedNode.startsWith(renderedIndentation)
? renderedNode
: `${renderedIndentation}${renderedNode}`;

return renderedNodeWithIndentation;

const renderedSubNode = renderNode(ctx, subNode);
return renderWithIndentation(ctx, renderedSubNode);
}).filter(renderedChild => renderedChild !== "")
.join(renderedNewLine);

Expand Down
5 changes: 2 additions & 3 deletions src/renderer/markup/html/ast/paragraph.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { renderIndentation } from "unwritten:renderer/utils/indentation";
import { renderWithIndentation } from "unwritten:renderer/utils/indentation";
import { renderNode } from "unwritten:renderer:html/index";

import type { HTMLRenderContext } from "unwritten:renderer:markup/types-definitions/markup";
Expand All @@ -7,11 +7,10 @@ import type { ParagraphNode } from "unwritten:renderer:markup/types-definitions/

export function renderParagraphNode(ctx: HTMLRenderContext, paragraphNode: ParagraphNode): string {

const renderedIndentation = renderIndentation(ctx);
const renderedNode = renderNode(ctx, paragraphNode.children);

return renderedNode === ""
? renderedNode
: `${renderedIndentation}<p>${renderedNode}</p>`;
: renderWithIndentation(ctx, `<p>${renderedNode}</p>`);

}
7 changes: 3 additions & 4 deletions src/renderer/markup/html/ast/section.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { withIndentation } from "unwritten:renderer/markup/utils/context";
import { getRenderConfig } from "unwritten:renderer/utils/config";
import { renderIndentation } from "unwritten:renderer/utils/indentation";
import { renderWithIndentation } from "unwritten:renderer/utils/indentation";
import { renderNewLine } from "unwritten:renderer/utils/new-line";
import { renderNode } from "unwritten:renderer:html/index";

Expand All @@ -14,7 +14,6 @@ export function renderSectionNode(ctx: HTMLRenderContext, sectionNode: SectionNo
const tag = getTag(ctx, sectionNode.type);
const classAttribute = sectionNode.type ? ` class="${sectionNode.type}"` : "";

const renderedIndentation = renderIndentation(ctx);
const renderedNewLine = renderNewLine(ctx);
const renderedOpeningTag = `<${tag}${classAttribute}>`;
const renderedTitle = withIndentation(ctx, ctx => renderNode(ctx, sectionNode.title));
Expand All @@ -24,10 +23,10 @@ export function renderSectionNode(ctx: HTMLRenderContext, sectionNode: SectionNo
return renderedChildren === "" && renderedTitle === ""
? ""
: [
`${renderedIndentation}${renderedOpeningTag}`,
renderWithIndentation(ctx, renderedOpeningTag),
renderedTitle,
renderedChildren,
`${renderedIndentation}${renderedClosingTag}`
renderWithIndentation(ctx, renderedClosingTag)
]
.filter(renderedNode => !!renderedNode)
.join(renderedNewLine);
Expand Down
6 changes: 2 additions & 4 deletions src/renderer/markup/html/ast/title.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getAnchorId, hasAnchor, unregisterAnchor } from "unwritten:renderer/markup/registry/registry";
import { withNesting } from "unwritten:renderer/markup/utils/context";
import { renderIndentation } from "unwritten:renderer/utils/indentation";
import { renderWithIndentation } from "unwritten:renderer/utils/indentation";
import { renderNewLine } from "unwritten:renderer/utils/new-line";
import { renderNode } from "unwritten:renderer:html/index";

Expand All @@ -10,7 +10,6 @@ import type { TitleNode } from "unwritten:renderer:markup/types-definitions/node

export function renderTitleNode(ctx: HTMLRenderContext, titleNode: TitleNode): string {

const renderedIndentation = renderIndentation(ctx);
const title = renderNode(ctx, titleNode.title);

const id = hasAnchor(titleNode)
Expand All @@ -19,8 +18,7 @@ export function renderTitleNode(ctx: HTMLRenderContext, titleNode: TitleNode): s

const idAttribute = id ? ` id="${id}"` : "";

const renderedTitle = `${renderedIndentation}<h${ctx.nesting}${idAttribute}>${title}</h${ctx.nesting}>`;

const renderedTitle = renderWithIndentation(ctx, `<h${ctx.nesting}${idAttribute}>${title}</h${ctx.nesting}>`);
const renderedChildren = withNesting(ctx, ctx => titleNode.children.map(child => renderNode(ctx, child)));

if(renderedChildren.every(renderedChild => renderedChild === "")){
Expand Down
9 changes: 4 additions & 5 deletions src/renderer/markup/markdown/ast/inline-title.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { renderMultilineArray } from "unwritten:renderer/markup/markdown/ast/mul
import { renderNode } from "unwritten:renderer/markup/markdown/index";
import { encapsulate } from "unwritten:renderer/markup/utils/renderer";
import { getRenderConfig } from "unwritten:renderer/utils/config";
import { renderIndentation } from "unwritten:renderer/utils/indentation";
import { renderWithIndentation } from "unwritten:renderer/utils/indentation";
import { renderNewLine } from "unwritten:renderer/utils/new-line";
import { renderEmptyLine } from "unwritten:renderer:markdown/utils/empty-line";
import { renderEmptyLine, startsWithEmptyLine } from "unwritten:renderer:markdown/utils/empty-line";

import type { MarkdownRenderContext } from "unwritten:renderer:markup/types-definitions/markup";
import type { InlineTitleNode } from "unwritten:renderer:markup/types-definitions/nodes";
Expand All @@ -13,14 +13,13 @@ import type { InlineTitleNode } from "unwritten:renderer:markup/types-definition
export function renderInlineTitleNode(ctx: MarkdownRenderContext, inlineTitleNode: InlineTitleNode): string {

const renderConfig = getRenderConfig(ctx);
const renderedIndentation = renderIndentation(ctx);

const renderedTitle = renderNode(ctx, inlineTitleNode.title);
const encapsulatedTitle = renderNode(
ctx,
encapsulate(`${renderedTitle}:`, renderConfig.inlineTitleEncapsulation)
);
const indentedTitle = `${renderedIndentation}${encapsulatedTitle}`;
const indentedTitle = renderWithIndentation(ctx, encapsulatedTitle);

const renderedNewLine = renderNewLine(ctx);
const renderedEmptyLine = renderEmptyLine(ctx);
Expand All @@ -30,7 +29,7 @@ export function renderInlineTitleNode(ctx: MarkdownRenderContext, inlineTitleNod
return "";
}

const childrenBeginsWithEmptyLine = renderedChildren.startsWith(renderedEmptyLine + renderedNewLine);
const childrenBeginsWithEmptyLine = startsWithEmptyLine(ctx, renderedChildren);
const trailingEmptyLine = childrenBeginsWithEmptyLine ? "" : renderedEmptyLine;

return [
Expand Down
26 changes: 14 additions & 12 deletions src/renderer/markup/markdown/ast/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { renderEmptyLine } from "unwritten:renderer/markup/markdown/utils/empty-
import { withIndentation } from "unwritten:renderer/markup/utils/context";
import { renderNewLine } from "unwritten:renderer/utils/new-line";
import { isListNode } from "unwritten:renderer:markup/typeguards/renderer";
import { renderIndentation as renderIndentationOriginal } from "unwritten:renderer:utils/indentation";
import {
renderIndentation,
renderWithIndentation as renderWithIndentationOriginal
} from "unwritten:renderer:utils/indentation";

import { renderNode } from "../index";

Expand Down Expand Up @@ -78,11 +81,10 @@ function renderListItem(ctx: MarkdownRenderContext, item: ASTNode): string {
return "";
}


// Remove indentation from rendered item
const renderedOriginalIndentation = renderIndentationOriginal(ctx);
const renderedItemWithoutOriginalIndentation = renderedArrayItems.startsWith(renderedOriginalIndentation)
? renderedArrayItems.slice(renderedOriginalIndentation.length)
const renderedIndentation = renderIndentation(ctx);
const renderedItemWithoutOriginalIndentation = renderedArrayItems.startsWith(renderedIndentation)
? renderedArrayItems.slice(renderedIndentation.length)
: renderedArrayItems;

// Collapse multiple new lines into one
Expand All @@ -91,7 +93,7 @@ function renderListItem(ctx: MarkdownRenderContext, item: ASTNode): string {
renderedNewLine
);

return `${renderIndentation(ctx)}- ${collapsedRenderedItem}`;
return renderWithIndentation(ctx, `- ${collapsedRenderedItem}`);

}

Expand All @@ -107,9 +109,9 @@ function renderListItem(ctx: MarkdownRenderContext, item: ASTNode): string {
}

// Remove indentation from rendered item
const renderedOriginalIndentation = renderIndentationOriginal(ctx);
const renderedItemWithoutOriginalIndentation = renderedItem.startsWith(renderedOriginalIndentation)
? renderedItem.slice(renderedOriginalIndentation.length)
const renderedIndentation = renderIndentation(ctx);
const renderedItemWithoutOriginalIndentation = renderedItem.startsWith(renderedIndentation)
? renderedItem.slice(renderedIndentation.length)
: renderedItem;

// Collapse multiple new lines into one
Expand All @@ -118,7 +120,7 @@ function renderListItem(ctx: MarkdownRenderContext, item: ASTNode): string {
renderedNewLine
);

return `${renderIndentation(ctx)}- ${collapsedRenderedItem}`;
return renderWithIndentation(ctx, `- ${collapsedRenderedItem}`);

}

Expand Down Expand Up @@ -177,9 +179,9 @@ function renderArrayItems(ctx: MarkdownRenderContext, items: ASTNode[]): string

}

function renderIndentation(ctx: MarkdownRenderContext): string {
function renderWithIndentation(ctx: MarkdownRenderContext, renderedNode: string): string {
ctx.indentation--;
const indentation = renderIndentationOriginal(ctx);
const indentation = renderWithIndentationOriginal(ctx, renderedNode);
ctx.indentation++;
return indentation;
}
12 changes: 5 additions & 7 deletions src/renderer/markup/markdown/ast/multiline.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { renderEmptyLine } from "unwritten:renderer/markup/markdown/utils/empty-line";
import { renderIndentation } from "unwritten:renderer/utils/indentation";
import { renderEmptyLine, startsWithEmptyLine } from "unwritten:renderer/markup/markdown/utils/empty-line";
import { renderWithIndentation } from "unwritten:renderer/utils/indentation.js";
import { renderNewLine } from "unwritten:renderer/utils/new-line";
import { renderNode } from "unwritten:renderer:markdown/index";

Expand All @@ -21,7 +21,6 @@ export function renderMultilineArray(ctx: MarkdownRenderContext, children: ASTNo
.reduce<string[]>((acc, child) => {

const renderedNode = renderNode(ctx, child);
const renderedIndentation = renderIndentation(ctx);

if(renderedNode === ""){
return acc;
Expand All @@ -37,16 +36,15 @@ export function renderMultilineArray(ctx: MarkdownRenderContext, children: ASTNo

// Remove empty line if previously rendered node ends with an empty line and the current node starts with an empty line
const renderedNodeWithoutDoubleEmptyLines = acc.at(-1)?.endsWith(renderedNewLine + renderedEmptyLine) &&
renderedNode.startsWith(renderedEmptyLine + renderedNewLine)
startsWithEmptyLine(ctx, renderedNode)
? renderedNode.slice((renderedEmptyLine + renderedNewLine).length)
: renderedNode;

// Render indentation for all children except empty lines
const renderedNodeWithIndentation =
renderedNodeWithoutDoubleEmptyLines.startsWith(renderedEmptyLine + renderedNewLine) ||
renderedNodeWithoutDoubleEmptyLines.startsWith(renderedIndentation)
startsWithEmptyLine(ctx, renderedNodeWithoutDoubleEmptyLines)
? renderedNodeWithoutDoubleEmptyLines
: `${renderedIndentation}${renderedNodeWithoutDoubleEmptyLines}`;
: renderWithIndentation(ctx, renderedNodeWithoutDoubleEmptyLines);

acc.push(renderedNodeWithIndentation);

Expand Down
Loading

0 comments on commit d4ebf83

Please sign in to comment.