Ace Code Editor

repository·master·Indexed 12 days ago

https://github.com/ajaxorg/ace

A standalone, browser-based source code highlighting editor written in JavaScript. Designed to match the features and performance of native editors like TextMate or Vim, Ace can be embedded into any web application. Version 1.44.0 provides a full-featured editing experience and powers the Cloud9 IDE.

Tokens
21.5K
Snippets
74
Records
104
Agent score
98%

What's inside Ace

  1. Configure AsciiDoc via Configuration Files

    master

    AsciiDoc behavior is controlled by cascading configuration files. Sections are defined by [section_name].

    Cascading Logic:

    • Sections prefixed with + (e.g., [+attributes]) append to existing sections.
    • Other sections override previous definitions.
    • A blank section (no entries) deletes the preceding section of the same name.

    Key Configuration Sections:

    • [miscellaneous]: Global options like newline, outfilesuffix, tabsize.
    • [attributes]: Predefined attribute name/value pairs.
    • [tags]: Backend markup tag definitions (e.g., emphasis=<em>|</em>).
    • [specialcharacters]: Escaping rules for backend-reserved characters.
    • [quotes]: Defines characters used for text formatting (e.g., _=emphasis).
    • [specialwords]: Defines words that trigger specific markup (e.g., strongwords=NOTE).
    • [macros]: Syntax definitions for macros.
    • [titles]: Patterns for section and block titles.

    Entry Syntax:

    • name=value:: Sets the value.
    • name=:: Sets value to an empty string.
    • name!:: Undefines/deletes the entry (only in attributes and miscellaneous).
  2. Structure an AsciiDoc document

    master

    An AsciiDoc document is composed of several hierarchical elements:

    1. Header (Optional): Contains metadata like title, author, and revision information. Must be followed by blank lines.
    2. Preamble (Optional): An untitled section body located between the Header and the first Section.
    3. Sections: The core content, organized into up to four levels (1 to 4). Sections are delimited by section titles.

    Document Hierarchy

    • Document $\rightarrow$ Header $\rightarrow$ Preamble $\rightarrow$ Sections
    • Section $\rightarrow$ SectionBody $\rightarrow$ Blocks (Paragraphs, Lists, Tables, etc.)
  3. Append content to list items using list continuations

    master

    To append block elements (like paragraphs or code blocks) to a list item, use a 'list continuation'—a separator line containing a single plus character (+). Without this, subsequent blocks are treated as new, separate elements.

    1. List item one.
    +
    List item one continued with a second paragraph.
    +
    [source,python]
    ----
    print('Hello')
    ----
  4. Define and Use Document Attributes

    master

    Document attributes are used for textual substitution using the {name} syntax. They are case-insensitive and can contain alphanumeric characters, dashes, and underscores.

    Defining Attributes

    Attributes can be defined in the document header or via AttributeEntry blocks:

    :author: Stuart Rackham
    :email: srackham@gmail.com

    To delete (undefine) an attribute, use:

    :name!:

    Attribute Precedence (Highest to Lowest)

    1. Command-line attributes
    2. AttributeEntry, AttributeList, Macro, and BlockId elements
    3. Configuration file [attributes] sections
    4. Intrinsic attributes

    Conditional Inclusion

    If an attribute is undefined, the line containing its reference is dropped. This is useful for conditional markup.

    :author: Stuart Rackham
    :email: srackham@gmail.com
    
    See the {author} at {email}.
  5. Use Macros in AsciiDoc

    master

    Macros substitute parameterized text into documents. They follow the syntax <name>:<target>[<attrlist>] for inline macros and <name>::<target>[<attrlist>] for block macros.

    Inline Macros

    • URLs: http, https, ftp, file, mailto, and callto are predefined. Example: http://example.com[Caption].
    • Internal Cross References:
      • anchor:[<id>,<xreflabel>]: Sets a hypertext link target. Use [[<id>]] for the block equivalent.
      • xref:<id>[<caption}]: Creates a link to an anchor ID.
    • Links to Local Files: link:<target>[<caption>] generates relative URLs.
    • Images: image:<target>[<attributes>]. Common attributes include alt, title, width, height, link, align (center, left, right), and float (HTML only).

    Block Macros

    • Block Identifier: [[<id>]] sets the ID for a block element.
    • Images: image::<target>[<attributes>] displays images in a block context. Can be preceded by a BlockTitle for automatic numbering in DocBook.
    • Comment Lines: // This is a comment. (only visible if showcomments attribute is defined).
    • Include Macros: include::<file>[<attributes>] includes file contents. Use include1:: for verbatim inclusion without processing.
    image:images/logo.png["Company Logo",height=32]
    
    [[tiger_image]]
    .Tyger tyger
    image::tiger.png[]
    
    This can be seen in <<tiger_image>>.
  6. How AsciiDoc filters work

    master

    Filters are an extension mechanism that allow external UNIX commands to process content within 'Paragraphs', 'DelimitedBlocks', and 'Tables'. They are primarily used to generate specialized outputs (e.g., syntax highlighting or diagram generation).

    Implementation Details

    • Mechanism: Filters read text from standard input, process it, and write to standard output.
    • Execution: Attribute expansion is performed on the filter command before execution, allowing you to pass parameters from the AsciiDoc source to the filter.
    • Installation: Use the asciidoc(1) command with the --filter option to install, remove, or unconditionally load a filter.
    • Search Paths: If a command doesn't specify a directory, asciidoc(1) searches in this order:
      1. $HOME/.asciidoc/filters
      2. Global filters directory (e.g., /etc/asciidoc/filters or /usr/local/etc/asciidoc)
      3. The ./filters directory relative to the asciidoc(1) executable.
      4. The system $PATH.

    Best Practices

    • Organization: Install each filter in its own sub-directory named after the filter's style definition (e.g., filters/music/).
    • Configuration: Filters are typically implemented by adding a <<style>> to existing Paragraph or ListingBlock definitions in configuration files.
    # Install a filter
    asciidoc --filter <filter_name>
    
    # Unconditionally load a filter
    asciidoc --filter <filter_name>
  7. Apply themes to AsciiDoc documents

    master

    The theme attribute allows you to select an alternative CSS stylesheet and include additional JavaScript code.

    • Usage: Set the attribute via the command line --theme <name> or as an attribute theme=<name>.
    • Theme Structure: Themes must reside in a configuration directory under themes/<theme>/. A theme requires a <theme>.css file (which replaces asciidoc.css) and can optionally include a <theme>.js file.
    • Built-in Themes: AsciiDoc includes flask and volnitsky themes.
    • Icons: If the data-uri attribute is defined, icons are loaded from the theme's icons sub-directory.
    # Using the command line option
    $ asciidoc --theme foo article.txt
    
    # Using the attribute
    $ asciidoc -a theme=foo article.txt
  8. Use AsciiDoc plugins to extend backends, filters, and themes

    master

    The AsciiDoc plugin architecture allows users to add new backends, filters, and themes via Zip files.

    Plugin Management

    You can manage plugins using the asciidoc(1) command-line options --backend, --filter, and --theme. These options support the following management commands:

    • install
    • list
    • remove
    • build

    Key Rules

    • Precedence: Filter plugins take precedence over built-in filters with the same name.
    • Installation Path: By default, filter plugins are installed in $HOME/.asciidoc/filters/<filter_name>.
    • Naming Convention: The plugin Zip file name must begin with the name of the backend, filter, or theme it contains.
    # Example plugin management commands
    asciidoc --filter install <plugin_name>
    asciidoc --filter list
  9. Specify AsciiDoc document types

    master

    AsciiDoc supports three primary document types. You can specify the type using the asciidoc(1) -d or --doctype option. The default type is article.

    TypeDescription
    articleUsed for short documents and general documentation. Supports standard DocBook article frontmatter and backmatter (appendix, abstract, bibliography, etc.).
    bookUsed for longer works. Shares the same format as articles but supports book-specific sections like preface and colophon, and handles complex DocBook features like automatic indexes and tables of contents.
    manpageUsed to generate roff format UNIX manual pages. Requires special header title and section naming conventions.

    By convention, AsciiDoc source files use the .txt extension.

  10. Build and package Ace

    master

    Ace uses the dryice build tool. Before building, ensure all submodules are initialized.

    • To create a standard package: use ./Makefile.dryice.js normal.
    • To create a bookmarklet version: use ./Makefile.dryice.js bm.

    Output files are placed in the build directory.

    # Initialize submodules first
    git submodule update --init --recursive
    
    # Build normal version
    ./Makefile.dryice.js normal
    
    # Build bookmarklet version
    ./Makefile.dryice.js bm
  11. Create enumerated, bulleted, and definition lists in reStructuredText

    master

    Lists must always start after a blank line (a new paragraph).

    Enumerated Lists

    Use numbers, letters, or roman numerals followed by a period ., a right bracket ), or surrounded by brackets ( ).

    Bulleted Lists

    Use bullet point characters: -, +, or *.

    Definition Lists

    Consist of a term followed by its definition. The definition must be indented relative to the term. Blank lines are not allowed between the term and its definition.

    1. numbers
    A. upper-case letters
    a. lower-case letters
    
    * bullet point
      - sub-list
    
    term
      definition of the term
  12. Build and package Ace with dryice

    master

    While you usually don't need to build Ace (you can use ace-builds), you can package it using the dryice build tool.

    First, install dependencies:

    npm install

    Then, run the build script:

    node ./Makefile.dryice.js

    Build Options:

    • -m: Minify build files with uglify-js.
    • -nc: Namespace require and define calls with "ace".
    • -bm: Build the bookmarklet version.
    • --target ./path: Specify the relative path for the output folder (default is ./build).

    To generate all files for the ace-builds repository:

    node Makefile.dryice.js full --target ../ace-builds
    npm install
    node ./Makefile.dryice.js