Skip to content

Commit

Permalink
Handle special headings
Browse files Browse the repository at this point in the history
  • Loading branch information
sourishkrout committed Oct 11, 2022
1 parent ee07eb1 commit 5a15e36
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
6 changes: 5 additions & 1 deletion internal/renderer/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ func (r *renderer) getRange(n ast.Node, start int, stop int) (string, error) {
case ast.KindHeading:
heading := n.(*ast.Heading)
offset := 1 + heading.Level
// shield from inital ======= vs ### heading
if start-offset < 0 {
offset = 0
}
_, _ = content.Write(r.source[start-offset : stop])
default:
_, _ = content.Write(r.source[start:stop])
Expand All @@ -165,7 +169,7 @@ func (r *renderer) getRange(n ast.Node, start int, stop int) (string, error) {
func (r *renderer) getPrevStart(n ast.Node) int {
curr := n
prev := n.PreviousSibling()
if prev != nil {
if prev != nil && prev.Lines().Len() > 0 {
curr = prev
}
return curr.Lines().At(0).Stop
Expand Down
1 change: 1 addition & 0 deletions internal/renderer/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var testCases = []string{
"singleblock",
"doublecode",
"nocodeblock",
"equalvshash",
}

func TestParser_Renderer(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"document":[{"markdown":"An Awesome VSCode Extension\n===========================\n\n[![Tests](https://github.com/stateful/vscode-awesome-ux/actions/workflows/test.yaml/badge.svg)](https://github.com/stateful/vscode-awesome-ux/actions/workflows/test.yaml)\n![vscode version](https://vsmarketplacebadge.apphb.com/version/stateful.awesome-ux.svg)\n![number of installs](https://vsmarketplacebadge.apphb.com/installs/stateful.awesome-ux.svg)\n![average user rating](https://vsmarketplacebadge.apphb.com/rating/stateful.awesome-ux.svg)\n![license](https://img.shields.io/github/license/stateful/vscode-awesome-ux.svg)\n\nThis extension is a best practices guide for writing great VSCode extensions. It can be used as boilerplate template to start of with a new extension.\n\n## Features\n\nIn itself this extension doesn't do much. It has some webviews, panels and commands implemented to show you how to interact with the [VSCode APIs](https://code.visualstudio.com/api/references/vscode-api).\n\nThe current version looks as follows:\n\n![Demo](./.github/assets/vscode.gif)\n\n## Best Practices\n\nWe have accumulated a set of best practices while developing VSCode extensions. Please note that these are just recommendations, sometimes based on personal preference. There are many ways to write an extension, and we found the following allow you to write them in a scaleable and testable way:\n\n- [Initiate Extensions through an `ExtensionController`](./docs/ExtensionController.md)\n- [Building WebViews](./docs/WebViews.md)\n\nIf you have more best practices, please share them with us by raising a PR or [filing an issue](https://github.com/stateful/vscode-awesome-ux/issues/new).\n\n## Extension Settings\n\nThis extension contributes the following settings:\n\n* `vscode-awesome-ux.configuration.defaultNotifications`: The default value of received example notification (default `0`)\n\n## Release Notes\n\nSee [release section](https://github.com/stateful/vscode-awesome-ux/releases).\n\n---\n\n\u003cp align=\"center\"\u003e\u003csmall\u003eCopyright 2022 © \u003ca href=\"http://stateful.com/\"\u003eStateful\u003c/a\u003e – MIT License\u003c/small\u003e\u003c/p\u003e"}]}
41 changes: 41 additions & 0 deletions internal/renderer/testdata/equalvshash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
An Awesome VSCode Extension
===========================

[![Tests](https://github.com/stateful/vscode-awesome-ux/actions/workflows/test.yaml/badge.svg)](https://github.com/stateful/vscode-awesome-ux/actions/workflows/test.yaml)
![vscode version](https://vsmarketplacebadge.apphb.com/version/stateful.awesome-ux.svg)
![number of installs](https://vsmarketplacebadge.apphb.com/installs/stateful.awesome-ux.svg)
![average user rating](https://vsmarketplacebadge.apphb.com/rating/stateful.awesome-ux.svg)
![license](https://img.shields.io/github/license/stateful/vscode-awesome-ux.svg)

This extension is a best practices guide for writing great VSCode extensions. It can be used as boilerplate template to start of with a new extension.

## Features

In itself this extension doesn't do much. It has some webviews, panels and commands implemented to show you how to interact with the [VSCode APIs](https://code.visualstudio.com/api/references/vscode-api).

The current version looks as follows:

![Demo](./.github/assets/vscode.gif)

## Best Practices

We have accumulated a set of best practices while developing VSCode extensions. Please note that these are just recommendations, sometimes based on personal preference. There are many ways to write an extension, and we found the following allow you to write them in a scaleable and testable way:

- [Initiate Extensions through an `ExtensionController`](./docs/ExtensionController.md)
- [Building WebViews](./docs/WebViews.md)

If you have more best practices, please share them with us by raising a PR or [filing an issue](https://github.com/stateful/vscode-awesome-ux/issues/new).

## Extension Settings

This extension contributes the following settings:

* `vscode-awesome-ux.configuration.defaultNotifications`: The default value of received example notification (default `0`)

## Release Notes

See [release section](https://github.com/stateful/vscode-awesome-ux/releases).

---

<p align="center"><small>Copyright 2022 © <a href="http://stateful.com/">Stateful</a> – MIT License</small></p>

0 comments on commit 5a15e36

Please sign in to comment.