Giter Club home page Giter Club logo

suse-vscode-doc's Introduction

Using VSCode as a SUSE technical writer

Introduction

VSCode is an IDE with an advanced text editor. It comes in 2 flavors:

  • Code - proprietary with closed-source licensed plugins
  • Codium - community driven build based on open-source software

You can use either Code or Codium according to your personal preference.

Extensions

Extensions extend VSCode's basic functionality. They are available from VSCode marketplaces:

You will need to download the following VSCode extensions:

  • XML - basic XML support
  • AsciiDoc - basic AsciiDoc support (requires ruby<RUBY_VERSION>-rubygem-asciidoctor package installed)
  • DAPS - run daps commands from VSCode (requires daps package installed)
  • Vale VSCode - document style checker (requires vale package installed)
  • SUSE Vale rules - set of style checker rules that follow SUSE style guide
  • Code Spell Checker - spell checker
  • DocBook Snippets - snippets that automate inserting simple and complex DB structures
  • HTML / XML / RSS link checker - checks XML links and finds HTTPs alternatives
  • Rewrap - aligns the flow of a paragraph

TIP: you can install them from the editor by pressing CTRL+SHIFT+X and typing the name of the extension.

Configuration

VSCode stores its configuration in settings.json files. Settings apply either globally (user settings) or to the current workspace.

User settings are stored in one of the following directories:

  • ~/.config/Code/User/ (VSCode)
  • ~/.config/VSCodium/User/ (VSCodium)

TIP: Access user settings by pressing CTRL+SHIFT+P, then typing json and selecting Preferences: Open User Settings (JSON)

Settings for the current workspace are stored in its .vscode subdirectory and override user settings.

XML: common settings

"xml.catalogs": [ // path to a system-wide XML catalog
    "/etc/xml/catalog"
],
"xml.validation.resolveExternalEntities": true, // enable XML entity processing
"xml.validation.xInclude.enabled": false, // turn off xInclude parsing, it does not work
"xml.codeLens.enabled": true, // display info about referencing and referenced lines

XML: support for RELAX NG schema

To let VSCode be aware of GeekoDoc and DocBook assembly schemas, you have two options:

  • RECOMMENDED: associate XML files based on a file suffix, for example, *.xml. The drawback is that all files with the suffix are associated, no matter whether it is a DocBook file or not.
"xml.fileAssociations": [
    {
        "pattern": "**/*.asm.xml",
        "systemId": "file:///usr/share/xml/docbook/schema/rng/5.2/assemblyxi.rng"
    },
    {
        "pattern": "**/*.xml",
        "systemId": "file:///usr/share/xml/geekodoc/rng/geekodoc-latest-flat.rng"
    }
    ],
  • ALTERNATIVE: insert an XML model definition at the top of the XML file before the root element (for example, after <?xml version="1.0"/>).
    • for GeekoDoc files:

      <?xml-model href="urn:x-suse:rng:v2:geekodoc-flat"
          type="application/xml"
          schematypens="http://relaxng.org/ns/structure/1.0"?>
    • for DocBook assmbly files:

      <?xml-model href="https://cdn.docbook.org/schema/5.2/rng/assemblyxi.rng"
          type="application/xml"
          schematypens="http://relaxng.org/ns/structure/1.0"?>

Spell checker

Install the Code Spell Checker extension

Basic settings

Following are useful settings. Consider adding them to settings.json:

"cSpell.enabled": true,
"cSpell.caseSensitive": true,
"cSpell.minWordLength": 3,
"cSpell.showAutocompleteSuggestions": true,
"cSpell.enabledLanguageIds": [
    "xml",
    "asciidoc",
    "markdown"
],

Spellchecker: custom dictionaries

To include SUSE's dictionary, install the suse-documentation-dicts-en package and the following to VSCode settings:

"cSpell.customDictionaries": {
    "SUSE custom": {
        "name": "SUSE custom dictionary",
        "path": "/usr/share/hunspell/en_US-suse-doc.dic",
        "addWords": false,
    },
    "SUSE adWords": {
        "name": "SUSE adWords dictionary",
        "path": "~/SUSE-adWords-dict.dic",
        "addWords": true,
    }
},

The first dictionary is read-only and enhances the common English language with in-house collected technical terms. The second one is your local writable dictionary to collect still-unknown words.

Spellchecker: ignoring strings

You can ignore specific strings such as XML markup from being spell-checked.

"cSpell.ignoreRegExpList": [
    "/<(\n|.)*?>/g",
    "/<\/.*?>/g",
    "/&.*;/g",
    "/<(screen|command|package|option|filename|systemitem|literal|guimenu|envar|remark).*?>(\n|.)*?</(\\1)>/g",
    "/:[a-zA-Z_-]+:/",
    "/----\n[\\S\\s]+?\n----/",
    "/```\n[\\S\\s]+?\n```/"
],

Spellchecker: marking as incorrect

You can insert a list of phrases that are always considered incorrectly spelled.

"cSpell.flagWords": [
    "filesystem"
],

DAPS integration

Refer to https://github.com/openSUSE/vscode-daps for more details.

DocBook snippets

Snippets are templates of complete DocBook structures. You can insert them into a document by typing predefined shortcuts. For example, pa inserts the following snippet and places the cursor between start and end tag: <para></para>.

AsciiDoc

Locked Preview to the Side is a nice feature, activate it by pressing CTRL+SHIFT+P, then typing asciidoc.

Tips

suse-vscode-doc's People

Contributors

tbazant avatar tomschr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

suse-vscode-doc's Issues

Add xml-model PI to README?

Problem

Issue #17 gave me no peace of mind. ๐Ÿ˜‰ The issue described the xml.fileAssociations option in the settings to associate a file extension with a (RNG) schema.

However, this has some drawbacks:

  • There is no exact 1:1 mapping from XML to a specific (RNG) schema. DocBook files can be any extension. Same with DITA.
  • Different (XML) files need different schemas. You can't validate a DITA XML file with the DocBook schema. If both have the same file extension, it will pick up the wrong schema.
  • The setting is more or less a convention. Although this is per se not bad, but it's not really general enough and works only for our specific use case.

Proposal

I think we can leave the xml.fileAssociations as it is. However, I would propose to extend the README. For this we need to test it first. If it works, we could add it to the text. If not, no harm is done and we can close this issue. ๐Ÿ˜‰

I'd suggest to investigate a bit time to look into the <?xml-model?> processing instruction (PI). It should be supported by VSCode now. This PI is included into the header of a XML file and acts like a reference. It points to a specific schema to be used for validation similar like a DOCTYPE for a DTD.

For RNG, it can be used in two ways:

  • PI for RELAX NG compact schema:

     <?xml-model href="URI" type="application/relax-ng-compact-syntax"?>
    
  • PI for a RELAX NG schema in XML format:

     <?xml-model href="URI"
                 type="application/xml"
                 schematypens="http://relaxng.org/ns/structure/1.0"?>
    

@tbazant: would you like to test a file with the above PIs and see if it gets validated?

References

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.