GithubHelp home page GithubHelp logo

mjbvz / vscode-markdown-languageservice Goto Github PK

View Code? Open in Web Editor NEW

This project forked from microsoft/vscode-markdown-languageservice

0.0 1.0 0.0 687 KB

The language service that powers VS Code's Markdown support, extracted so that it can be reused by other editors and tools

License: MIT License

JavaScript 0.87% TypeScript 99.13%

vscode-markdown-languageservice's Introduction

VS Code Markdown Language Service

The language service that powers VS Code's Markdown support, extracted so that it can be reused by other editors and tools.

Features

This library targets CommonMark. Support for other Markdown dialects and extensions is not within the scope of this project.

Currently supported language features:

  • Document links (clickable spans in the editor)

    Supported links include:

    • Links to headers within the current file: [text](#header)
    • Absolute and relative links to files: [text](path/to/file.md)
    • Reference links: [text][link-name]
  • Document symbols

    Finds all headers within a markdown file

  • Workspace symbols

    Find all headers across all markdown files in the workspace.

  • Folding ranges

    Folding ranges are computed for:

    • Header sections
    • Region sections
    • Lists
    • Block elements
  • Smart select (expand selection)

  • Completions

    Supports completions for:

    • Links to headers
    • Path links
    • Reference links
  • Find all references

    Supports finding references to:

    • Headers
    • Path links
    • Fragments in links
    • Reference links
  • Definitions

    Supports finding definitions headers and reference links.

  • Renames

    Supports renaming of headers and links.

  • Organize link definitions.

    Groups and sorts link definitions in a file, optionally also removing unused definitions.

  • Code actions

    • Extract all occurrences of a link in a file to a link definition at the bottom of the file.
    • Quick fixes for removing duplicated or unused link definitions.
  • Diagnostics (error reporting)

    Supports generating diagnostics for invalid links to:

    • References.
    • Header within the current file.
    • Files in the workspace.
    • Headers in other files.

    Also can generate diagnostics for:

    • Unused link definitions.
    • Duplicate link definitions.
  • Update links on file rename

    Generate an edit that updates all links when a file/directory in the workspace is renamed or moved.

Usage

To get started using this library, first install it into your workspace:

npm install vscode-markdown-languageservice

To use the language service, first you need to create an instance of it using createLanguageService. We use dependency injection to allow the language service to be used in as many contexts as possible.

import * as md from 'vscode-markdown-languageservice';

// Implement these
const parser: md.IMdParser = ...;
const workspace: md.IWorkspace = ...;
const logger: md.ILogger = ...;

const languageService = md.createLanguageService({ workspace, parser, logger });

After creating the service, you can ask it for the language features it supports:

// We're using the vscode-language types in this demo
// If you want to use them, make sure to run:
//
//     npm install vscode-languageserver vscode-languageserver-textdocument
//
// However you can also bring your own types if you want to instead.

import { CancellationTokenSource } from 'vscode-languageserver';
import { TextDocument } from 'vscode-languageserver-textdocument';

const cts = new CancellationTokenSource();

// Create a virtual document that holds our file content
const myDocument = TextDocument.create(
	URI.file('/path/to/file.md').toString(), // file path
	'markdown', // file language
	1, // version
	[ // File contents
		'# Hello',
		'from **Markdown**',
		'',
		'## World!',
	].join('\n')
);

const symbols = await languageService.getDocumentSymbols(myDocument, { includeLinkDefinitions: true }, cts.token);

See example.cjs for complete, minimal example of using the language service. You can run in using node example.cjs.

Additional Links

Contributing

If you're interested in contributing

  1. Clone this repo
  2. Install dependencies using npm install
  3. Start compilation using npm run watch

You can run the unit tests using npm test or by opening the project in VS Code and pressing F5 to debug.

vscode-markdown-languageservice's People

Contributors

mjbvz avatar microsoftopensource avatar lramos15 avatar lszomoru avatar bpasero avatar microsoft-github-operations[bot] avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.