### Install ExDoc as an escript Source: https://ex-doc.hexdocs.pm/ Install the ExDoc executable globally via Mix. ```bash $ mix escript.install hex ex_doc ``` -------------------------------- ### ExDoc command-line argument examples Source: https://ex-doc.hexdocs.pm/ Reference values for the ex_doc command-line arguments. ```text PROJECT_NAME => Ecto PROJECT_VERSION => 0.1.0 PROJECT_MODULE => Ecto (the main module provided by the library) GITHUB_USER => elixir-ecto GITHUB_REPO => ecto ``` -------------------------------- ### Define a Greeter module in Elixir Source: https://ex-doc.hexdocs.pm/cheatsheet.md A basic module definition and function call example. ```elixir # hello.exs defmodule Greeter do def greet(name) do message = "Hello, " <> name <> "!" IO.puts message end end Greeter.greet("world") ``` -------------------------------- ### Group extras by file path Source: https://ex-doc.hexdocs.pm/ExDoc.md Organize extra guides into groups using Path.wildcard to match file patterns. ```elixir groups_for_extras: [ "Introduction": Path.wildcard("guides/introduction/*.md"), "Advanced": Path.wildcard("guides/advanced/*.md") ] ``` -------------------------------- ### Group extras by regex Source: https://ex-doc.hexdocs.pm/ExDoc.md Organize extra guides into groups using regular expressions to match file paths. ```elixir groups_for_extras: [ "Introduction": ~r"/introduction/", "Advanced": ~r"/advanced/" ] ``` -------------------------------- ### Configure skip_code_autolink_to Source: https://ex-doc.hexdocs.pm/ExDoc.md Examples for skipping specific terms during documentation autolinking. ```elixir &String.match?(&1, ~r/PrivateModule/) ``` ```elixir ["PrivateModule", "PrivateModule.func/1"] ``` -------------------------------- ### Configure skip_undefined_reference_warnings_on Source: https://ex-doc.hexdocs.pm/ExDoc.md Examples for suppressing undefined reference warnings using lists or functions. ```elixir ["Foo", "Bar.baz/0"] ``` ```elixir &String.match?(&1, ~r/Foo/) ``` ```elixir ["pages/deprecations.md"] ``` -------------------------------- ### Define and access user map Source: https://ex-doc.hexdocs.pm/cheatsheet.md Example of map creation and string concatenation in Elixir. ```elixir user = %{ name: "John", city: "Melbourne" } ``` ```elixir IO.puts "Hello, " <> user.name ``` -------------------------------- ### Define Markdown layout variants Source: https://ex-doc.hexdocs.pm/cheatsheet.md Example of using inline attribute notation to change presentation. ```markdown ## H2 {: .col-2} ### H3 {: .list-6} * example 1 * example 2 ``` -------------------------------- ### ExDoc Development Commands Source: https://ex-doc.hexdocs.pm/ Standard shell commands for setting up, building, and linting the ExDoc project locally. ```bash 1. Run `mix setup` to install all dependencies 2. Run `mix build` to generate the docs and open up the generated `doc/index.html` 3. (optional) Run `erl -S httpd serve doc/` to serve the docs locally 4. (optional) Run `npm run --prefix assets build:watch` if working on assets for automatic recompilation 5. Run `mix lint` to check linting and formatting (and `mix fix` to automatically fix it) 6. (important) Do not add the files in the `formatters/` directory to your commits, those will be handled by the maintainers ``` -------------------------------- ### Generate project documentation with ExDoc Source: https://ex-doc.hexdocs.pm/ExDoc.md The generate function serves as the main entry point for creating documentation, requiring the project name, version, source directories, and configuration options. ```elixir @spec generate(String.t(), String.t(), [Path.t()], Keyword.t()) :: [ %{entrypoint: String.t(), warned?: boolean(), formatter: module()} ] ``` -------------------------------- ### Define run callback Source: https://ex-doc.hexdocs.pm/ExDoc.Formatter.md The primary entry point for formatters, receiving configuration and nodes to generate documentation output. ```elixir @callback run(ExDoc.Formatter.Config.t(), [ExDoc.ModuleNode.t()], [ ExDoc.ExtraNode.t() | ExDoc.URLNode.t() ]) :: %{entrypoint: String.t(), build: [String.t()]} ``` -------------------------------- ### Invoke ExDoc for umbrella projects Source: https://ex-doc.hexdocs.pm/ Specify multiple ebin directories when generating documentation for umbrella projects. ```bash $ ex_doc "PROJECT_NAME" "PROJECT_VERSION" _build/dev/lib/app1/ebin _build/dev/lib/app2/ebin -m "PROJECT_MODULE" -u "https://github.com/GITHUB_USER/GITHUB_REPO" -l path/to/logo.png ``` -------------------------------- ### Compile project for documentation Source: https://ex-doc.hexdocs.pm/ Ensure the project is compiled before running the ExDoc executable. ```bash $ cd PATH_TO_YOUR_PROJECT $ mix compile ``` -------------------------------- ### Configure Extra Documentation Pages Source: https://ex-doc.hexdocs.pm/ Define additional documentation files in your project configuration using the :extras key. ```elixir extras: ["README.md", "LICENSE", "tutorial.livemd", "cheatsheet.cheatmd"] ``` ```erlang {extras, [<<"README.md">>, <<"cheatsheet.cheatmd">>]}. ``` -------------------------------- ### Configure Documentation Redirects Source: https://ex-doc.hexdocs.pm/ExDoc.md Map old module or file paths to new locations to prevent broken links. Destinations can include anchors for specific sections. ```elixir redirects: %{ "MyApp.MyModule" => "MyApp.My.Module", "get-started" => "quickstart" } ``` ```elixir redirects: %{ "old-page" => "new-page#relevant-section" } ``` -------------------------------- ### Render Math with KaTeX Source: https://ex-doc.hexdocs.pm/ Load KaTeX libraries and trigger rendering on the 'exdoc:loaded' event to support TeX-style math expressions. ```html ``` -------------------------------- ### ExDoc.generate/4 Source: https://ex-doc.hexdocs.pm/ExDoc.md Generates documentation for a given project, version, source directories, and configuration options. ```APIDOC ## ExDoc.generate(project, vsn, source_beams, options) ### Description Generates documentation for the given project, version, source beams directories, and options. By default, it generates HTML, Markdown, and EPUB documents. ### Signature `generate(String.t(), String.t(), [Path.t()], Keyword.t()) :: [%{entrypoint: String.t(), warned?: boolean(), formatter: module()}]` ### Parameters - **project** (String.t) - The name of the project. - **vsn** (String.t) - The version of the project. - **source_beams** ([Path.t()]) - A list of paths to the compiled BEAM files. - **options** (Keyword.t) - Configuration options for the documentation generation. ### Options - **:annotations_for_docs** (function) - Function to add metadata annotations. - **:api_reference** (boolean) - Whether to generate api-reference.html; default: true. - **:assets** (map) - Map of source to target directories for assets. - **:authors** (list) - List of authors. - **:before_closing_body_tag** (function) - Function to inject HTML before . - **:before_closing_head_tag** (function) - Function to inject HTML before . - **:before_closing_footer_tag** (function) - Function to inject HTML before (HTML only). - **:canonical** (String.t) - Preferred URL for rel="canonical". - **:cover** (Path.t) - Path to epub cover image. - **:deps** (Keyword.t) - Map of application names to documentation URLs. - **:description** (String.t) - Brief project description. - **:extra_section** (String.t) - Title for additional pages; default: "Pages". - **:extras** (list) - List of additional Markdown/text files. - **:favicon** (Path.t) - Path to favicon image. - **:filter_modules** (regex/string/function) - Filter modules to include. - **:formatters** (list) - List of formatters; default: ["html", "markdown", "epub"]. - **:footer** (boolean) - Whether to render the footer. ``` -------------------------------- ### Invoke ExDoc executable Source: https://ex-doc.hexdocs.pm/ Run the ex_doc command with project details to generate documentation. ```bash $ ex_doc "PROJECT_NAME" "PROJECT_VERSION" _build/dev/lib/project/ebin -m "PROJECT_MODULE" -u "https://github.com/GITHUB_USER/GITHUB_REPO" -l path/to/logo.png ``` -------------------------------- ### Configure dependency documentation links Source: https://ex-doc.hexdocs.pm/readme.html Set the documentation URL for dependencies in project configuration files. ```elixir docs: [deps: [my_dep: "https://path/to/docs/"]] ``` ```erlang {docs, [{deps, [{my_dep, "https://path/to/docs/"}]}]} ``` -------------------------------- ### Generate documentation for umbrella projects Source: https://ex-doc.hexdocs.pm/Mix.Tasks.Docs.md Execute the docs task for every child application within an umbrella project. ```bash mix cmd mix docs ``` -------------------------------- ### Configure ExDoc in mix.exs Source: https://ex-doc.hexdocs.pm/Mix.Tasks.Docs.md Define documentation metadata and settings within the project function of your mix.exs file. ```elixir def project do [ app: :my_app, version: "0.1.0-dev", deps: deps(), # Docs name: "My App", source_url: "https://github.com/USER/PROJECT", homepage_url: "http://YOUR_PROJECT_HOMEPAGE", docs: [ main: "MyApp", # The main page in the docs favicon: "path/to/favicon.png", logo: "path/to/logo.png", extras: ["README.md"] ] ] end ``` -------------------------------- ### Configure Syntax Highlighting Source: https://ex-doc.hexdocs.pm/ Add language-specific Makeup packages to your project configuration to enable syntax highlighting. ```elixir {:makeup_html, ">= 0.0.0", only: :dev, runtime: false} ``` ```erlang {makeup_html, "0.1.1"} ``` -------------------------------- ### Configure source_url and source_ref in Elixir Source: https://ex-doc.hexdocs.pm/ExDoc.md Use these settings in your project configuration to link documentation directly to the specific version of the source code. ```elixir @version "0.30.10" def project do [ ... version: @version, source_url: "https://github.com/USER/PROJECT", docs: &docs/0 ] end def docs do [ ... source_ref: "v#{@version}" ] end ``` -------------------------------- ### version() Source: https://ex-doc.hexdocs.pm/ExDoc.md Returns the current version of the ExDoc library. ```APIDOC ## version() ### Description Returns the ExDoc version, which is typically used within templates. ### Signature `version() :: String.t()` ``` -------------------------------- ### to_ast(text, options) Source: https://ex-doc.hexdocs.pm/ExDoc.Markdown.Earmark.md Generates an HTML AST from the provided Markdown text based on the specified configuration options. ```APIDOC ## to_ast(text, options) ### Description Generates an HTML AST from the provided Markdown text using the Earmark parser. ### Parameters #### Options - **:gfm** (boolean) - Optional - Turns on Github Flavored Markdown extensions. Defaults to true. - **:breaks** (boolean) - Optional - Only applicable if gfm is enabled. Makes all line breaks significant. ``` -------------------------------- ### Join path segments Source: https://ex-doc.hexdocs.pm/cheatsheet.md Demonstrates path manipulation using Path.join. ```elixir Path.join(["~", "foo"]) "~/foo" ``` ```elixir Path.join(["foo"]) "foo" ``` -------------------------------- ### Configure Custom JavaScript Source: https://ex-doc.hexdocs.pm/ Inject custom scripts into documentation pages by updating the project configuration. ```elixir docs: [ ``` -------------------------------- ### Check availability of Markdown processor Source: https://ex-doc.hexdocs.pm/ExDoc.Markdown.md Callback to verify if the necessary dependencies for the Markdown processor are present. ```elixir @callback available?() :: boolean() ``` -------------------------------- ### Configure Module-Function Hooks Source: https://ex-doc.hexdocs.pm/ Pass a module-function-args tuple to the configuration to dynamically generate injected HTML. ```elixir docs: [ # ... before_closing_head_tag: {MyModule, :before_closing_head_tag, []}, before_closing_body_tag: {MyModule, :before_closing_body_tag, []} ] ``` -------------------------------- ### Render Mermaid Graphs Source: https://ex-doc.hexdocs.pm/ Initialize Mermaid to render diagrams, ensuring the initialization logic runs only once. ```javascript ``` -------------------------------- ### Define Custom HTML Injection Hooks Source: https://ex-doc.hexdocs.pm/ Use private functions to define HTML content injected into the head or body tags based on the output format. ```elixir defp before_closing_head_tag(:html) do """ """ end defp before_closing_head_tag(:epub), do: "" defp before_closing_body_tag(:html) do """ """ end defp before_closing_body_tag(:epub), do: "" ``` -------------------------------- ### Define spec_ast type Source: https://ex-doc.hexdocs.pm/ExDoc.DocNode.md Represents the abstract syntax tree for a specification. ```elixir @type spec_ast() :: term() ``` -------------------------------- ### Define ExDoc.ExtraNode type Source: https://ex-doc.hexdocs.pm/ExDoc.ExtraNode.md The type definition for the ExDoc.ExtraNode struct, detailing its fields and expected types. ```elixir @type t() :: %ExDoc.ExtraNode{ doc: ExDoc.DocAST.t() | nil, group: atom() | nil, id: String.t(), search_data: [map()] | nil, source_doc: String.t(), source_path: String.t(), source_url: String.t(), title: String.t(), title_doc: ExDoc.DocAST.t() | String.t(), type: atom() } ``` -------------------------------- ### Render Mermaid Diagrams with JavaScript Source: https://ex-doc.hexdocs.pm/ This script iterates through all Mermaid code blocks in the DOM and replaces them with rendered SVG elements. ```javascript let id = 0; for (const codeEl of document.querySelectorAll("pre code.mermaid")) { const preEl = codeEl.parentElement; const graphDefinition = codeEl.textContent; const graphEl = document.createElement("div"); const graphId = "mermaid-graph-" + id++; mermaid.render(graphId, graphDefinition).then(({svg, bindFunctions}) => { graphEl.innerHTML = svg; bindFunctions?.(graphEl); preEl.insertAdjacentElement("afterend", graphEl); preEl.remove(); }); } }); ``` -------------------------------- ### Define function_default type Source: https://ex-doc.hexdocs.pm/ExDoc.DocNode.md Represents a function default value as a tuple containing the name and arity. ```elixir @type function_default() :: {name :: atom(), arity :: non_neg_integer()} ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.