{"_id":"muggle-pug","_rev":"1699929","name":"muggle-pug","description":"Pug compiled to HTML as pieces that map to the pug code","dist-tags":{"latest":"0.1.0","next":"0.1.0-alpha.0"},"maintainers":[{"name":"johnsoncodehk","email":"johnsoncodehk@gmail.com"}],"time":{"modified":"2026-11-08T22:28:31.000Z","created":"2026-10-30T16:05:54.589Z","0.1.0":"2026-11-01T16:46:48.288Z","0.1.0-alpha.0":"2026-10-30T16:06:50.303Z","0.0.0-stage":"2026-10-30T16:05:54.589Z"},"users":{},"repository":{"url":"git+https://github.com/johnsoncodehk/muggle-pug.git","type":"git"},"versions":{"0.1.0":{"_id":"muggle-pug@0.1.0","bugs":{"url":"https://github.com/johnsoncodehk/muggle-pug/issues"},"dist":{"shasum":"d2440f7c66abaf4e44542dc8f067102e7aab97d6","tarball":"http://registry-npm.ywwl.com/muggle-pug/download/muggle-pug-0.1.0.tgz","fileCount":9,"integrity":"sha512-YA7LTVUWYr0M9W9J/SFC1iLo/XDPKR2uX2MWMxq39cWdtuTaTrkG7QpWNE6vP4dPQ/UKy5pXE7L1uBfJGysVaw==","signatures":[{"sig":"MEUCIQCgRFTr0/Xya7t0Gpuxvsf/G0WlEQ1ApfrS1Ux5oSwaswIgFpkT3zkMtLD5ouktgOe4iZGZcT33bf8jXx1+R+C5UaQ=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDBue6K+YV+enuUhipriOqBxZZnuOLoJwBQPiQIq81sfwIgIi9Asw9phuXqTAa6Uu83F2a31Io+OvndXW4moxqaf9E="}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/muggle-pug@0.1.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":28380,"size":8626,"noattachment":false,"key":"/muggle-pug/-/muggle-pug-0.1.0.tgz"},"name":"muggle-pug","type":"module","engines":{"node":"^20.19.0 || >=22.12.0"},"exports":{".":{"types":"./out/index.d.ts","default":"./out/index.js"}},"gitHead":"12ee2b7b76e27be712ce94c279894599c899493b","license":"MIT","scripts":{"test":"vitest run","build":"tsc"},"version":"0.1.0","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"ab273cdb-44b0-43d8-9638-684130651f0a"}},"homepage":"https://github.com/johnsoncodehk/muggle-pug#readme","repository":{"url":"git+https://github.com/johnsoncodehk/muggle-pug.git","type":"git"},"_npmVersion":"12.2.1","description":"Pug compiled to HTML as pieces that map to the pug code","directories":{},"maintainers":[{"name":"johnsoncodehk","email":"johnsoncodehk@gmail.com"}],"sideEffects":false,"_nodeVersion":"24.22.1","dependencies":{"pug-lexer":"^5.0.1","pug-parser":"^6.0.0","muggle-string":"^1.0.0"},"_hasShrinkwrap":false,"devDependencies":{"vitest":"latest","typescript":"7.1.0-beta","@types/node":"^26.0.1"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/muggle-pug_0.1.0_1793551608198_0.5093200592224971"},"publish_time":1793551608288,"_cnpm_publish_time":1793551608288},"0.1.0-alpha.0":{"name":"muggle-pug","version":"0.1.0-alpha.0","license":"MIT","_id":"muggle-pug@0.1.0-alpha.0","maintainers":[{"name":"johnsoncodehk","email":"johnsoncodehk@gmail.com"}],"homepage":"https://github.com/johnsoncodehk/muggle-pug#readme","bugs":{"url":"https://github.com/johnsoncodehk/muggle-pug/issues"},"dist":{"shasum":"3c6503a91cc3b69ceba9eeebd729cd5ee2937ca2","tarball":"http://registry-npm.ywwl.com/muggle-pug/download/muggle-pug-0.1.0-alpha.0.tgz","fileCount":9,"integrity":"sha512-alge3awp7rIgYsqTE0xinT8au4OjyoqANeD9AP7ushhcMt580doCdgk1maamXu1jILvWJyCF0+v6rkXSdtcz+Q==","signatures":[{"sig":"MEYCIQCwYTmD6q5RVKTnAP+VxyPuNjw7ZZnYW8f4qBrR5XrXDAIhAOt7vZQZARrKlkWZcZILhtNAJLA9iBDCnZz05nA0XVVW","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"sig":"MEQCIHgW7mAvTBFVLB5+SPHeYi5g5XzIdGr+lur8H6AiTzv+AiA2LXYyGpf4P0PdJ6Kup+OwPL3hNW6mzj8FpZAf4C7gkw==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":23899,"size":6853,"noattachment":false,"key":"/muggle-pug/-/muggle-pug-0.1.0-alpha.0.tgz"},"main":"out/index.js","types":"out/index.d.ts","scripts":{"test":"vitest run","build":"tsc"},"_npmUser":{"name":"johnsoncodehk","email":"johnsoncodehk@gmail.com"},"repository":{"url":"git+https://github.com/johnsoncodehk/muggle-pug.git","type":"git"},"_npmVersion":"12.0.1","description":"Pug compiled to HTML as pieces that map to the pug code","directories":{},"_nodeVersion":"24.15.0","dependencies":{"pug-lexer":"^5.0.1","pug-parser":"^6.0.0"},"_hasShrinkwrap":false,"devDependencies":{"vitest":"latest","typescript":"7.1.0-beta","@types/node":"^26.0.1","@vue/compiler-dom":"^3.5.0"},"_npmOperationalInternal":{"tmp":"tmp/muggle-pug_0.1.0-alpha.0_1793376410203_0.8191347014680969","host":"s3://npm-registry-packages-npm-production"},"publish_time":1793376410303,"_cnpm_publish_time":1793376410303},"0.0.0-stage":{"name":"muggle-pug","version":"0.0.0-stage","_id":"muggle-pug@0.0.0-stage","stub":true,"maintainers":[{"name":"johnsoncodehk","email":"johnsoncodehk@gmail.com"}],"dist":{"shasum":"32fe0436baeed12613a99a7f6228f70dc8232d35","tarball":"http://registry-npm.ywwl.com/muggle-pug/download/muggle-pug-0.0.0-stage.tgz","fileCount":2,"integrity":"sha512-qZfwYtHnn97uMnyAct3pO4oVVZbuzTnMp60UUrKr7k6KTv3QlISkj06mH54K/qA90AZAvD9PXImg3TzZO6vCWA==","signatures":[{"sig":"MEQCICRJlRtzHvyTDnt6WLdDp4Gk4FHoVcVWIOCgiHqaWkuoAiBGIbG91GnX/FHkeQdraVwMpVnNPRhNlt0xH7RaO4PsvA==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":332,"size":362,"noattachment":false,"key":"/muggle-pug/-/muggle-pug-0.0.0-stage.tgz"},"_npmUser":{"name":"johnsoncodehk","email":"johnsoncodehk@gmail.com"},"description":"Temporary package placeholder for staged publishing","directories":{},"publish_time":1793376354589,"_cnpm_publish_time":1793376354589}},"readme":"# muggle-pug\n\nI wrote muggle-pug for [vuejs/language-tools](https://github.com/vuejs/language-tools), so that a Vue template written in pug reads as HTML to the language server, and every result maps back to the pug code. It compiles pug to HTML as the pieces of [muggle-string](https://github.com/johnsoncodehk/muggle-string): ranges of the pug code, kept wherever the HTML is the pug code.\n\nIt depends only on `pug-lexer`, `pug-parser` and the `Piece` type of muggle-string, and builds no mappings: every consumer turns the pieces into the mappings of its own tooling.\n\n## Adoption\n\n- [vuejs/language-tools](https://github.com/vuejs/language-tools): compiles the pug templates of Vue single-file components for the language server. Its releases compile pug with muggle-string 0.4; the move to muggle-pug is in progress and not released.\n\n## Install\n\n`npm install muggle-pug`. It ships as ES modules only. CommonJS code can `require` it on Node 20.19 and later, or 22.12 and later.\n\n## Usage\n\n```ts\nimport { compile } from 'muggle-pug';\n\nconst pugCode = 'div.foo hello';\nconst { pieces, ast, error } = compile(pugCode);\n// pieces: [..., { start: 8, end: 13 }, ...]\nconst html = pieces.map(piece => typeof piece === 'string' ? piece : piece.text ?? pugCode.slice(piece.start, piece.end)).join('');\n// html: '<div class=\"foo\">hello</div>'\n```\n\n- `pieces`: the HTML, as muggle-string pieces of the pug code, with no `source` and no data. A range without `text` keeps the pug code at `start`..`end`. A range with `text` is HTML that stands for its range: `\"` for the `.` of `.foo`, or, as an empty range, a position, such as `<` at the start of a tag. A string, an end tag, stands for no range.\n- `ast`: the AST of pug-parser, with 1-based lines and columns of the pug code.\n- `error`: the first error of pug, with its `code`, `message`, `offset`, and 0-based `line` and `column`; `undefined` if there is none.\n\n## The HTML\n\nThe HTML is for tools, not what pug renders: an HTML parser reads it as the elements, attributes, text and comments written in the pug code, and each of them is the pug code where it can be. Nothing is evaluated, as a value that is not its code maps to nothing in it.\n\n- Attribute values, text and code are the pug code, byte for byte. pug's `class=\"a\" + b`, `` `${a}` `` or `'a\\'b'` is code that only pug's runtime gives a value; here it stays code.\n- What is not the pug code is the least that makes the HTML read right, one char for one where it can be:\n  - `<`, `>` and `/>` at positions. An element without content closes with `/>`, so that no void element has an end tag. An end tag stands for no range, followed by the end of the element as an empty range: as the range of the name, or as a position, a tool that edits or shows both names of an element, such as a rename or a highlight, would have the one range twice. An implicit `div` is at the position of the tag.\n  - A class or id literal, `.foo` or `#foo`, is ` class=\"` or ` id=\"` whose name and quote stand for its `.` or `#`, and `\"` at its end. Each is its own attribute, as `.foo(class=\"bar\")` makes two class attributes anyway (the Vue plugin of vuejs/language-tools ignores the duplicate).\n  - The parentheses, the commas and the quotes of a name of an attribute list are spaces, and so is the `!` of `!=`, so that the name is the name.\n  - A value that is one string or template literal is in quotes that are not in it: its own, or else `\"`, or else `'`. With both in it, its `\"` are `'`, so that the value ends where the literal does. The `\\` of a line continuation in it is a space, so that the value as an expression of Vue has no invalid char.\n  - A comment, `//-` too, is `<!--` for its `//` and `-->` at its end, for the directive comments of Vue, such as `@vue-ignore`.\n- Conditionals, loops, mixins and code add the markup inside them: every branch, once. Doctypes, includes, extends and filters add none.\n\n## Errors\n\npug stops at its first error, but a template that is being written still needs HTML. So muggle-pug leaves out the line that pug fails on, one at a time, until pug reads the rest: `pieces` and `ast` cover the other lines, and `error` is the first error.\n\n```ts\nconst { pieces, error } = compile('div\\n  p(cl\\n  span hi');\n// html: '<div><span>hi</span></div>'\n// error: { code: 'PUG:NO_END_BRACKET', line: 2, column: 9, ... }\n```\n\n`compile` does not throw: an error that pug throws without a position, such as the `TypeError` of `div#` at the end of the code, is at where pug stops, with the name or code of the error.\n\n## Indentation\n\nVue dedents a pug template, but pug reads an indented first line as text, so pug is given the template without the indentation that all its lines share; the pieces, the AST and the error are all of the written template.\n\n## Source map\n\nThe pieces carry no `source`, as all of them are of the one pug code. To render them with `renderWithSourceMap` of muggle-string, give each range its source:\n\n```ts\nimport { compile } from 'muggle-pug';\nimport { renderWithSourceMap } from 'muggle-string';\n\nconst source = { name: 'App.pug', content: 'div.foo hello' };\nconst { pieces } = compile(source.content);\nconst { text, map } = renderWithSourceMap(\n\tsink => pieces.forEach(piece => sink(typeof piece === 'string' ? piece : { ...piece, source })),\n\t(from: typeof source) => from.name,\n);\nconsole.log(text);\n// <div class=\"foo\">hello</div>\nconsole.log(map.mappings);\n// AAAA,CAAA,GAAG,CAAA,KAAA,CAAA,CAAC,GAAG,CAAA,CAAC,K;\nconsole.log(map.names);\n// [], as no HTML renames a name of the pug code\n```\n","_attachments":{},"homepage":"https://github.com/johnsoncodehk/muggle-pug#readme","bugs":{"url":"https://github.com/johnsoncodehk/muggle-pug/issues"},"license":"MIT"}