{"id":16057957,"url":"https://github.com/hedyhli/vento-plugin-trim-self","last_synced_at":"2026-04-28T20:02:02.940Z","repository":{"id":239915700,"uuid":"800975677","full_name":"hedyhli/vento-plugin-trim-self","owner":"hedyhli","description":"Automatically remove a trailing newline and indent around each template tag for Vento, based on context.","archived":false,"fork":false,"pushed_at":"2024-05-18T14:35:18.000Z","size":28,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-05T08:14:57.159Z","etag":null,"topics":["deno","plugin","vento"],"latest_commit_sha":null,"homepage":"https://deno.land/x/vento_plugin_trim_self","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hedyhli.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-15T11:07:07.000Z","updated_at":"2024-11-29T09:49:25.000Z","dependencies_parsed_at":"2024-05-18T06:20:36.346Z","dependency_job_id":"16886cda-c0a9-4af1-9d13-7cf7c653eac0","html_url":"https://github.com/hedyhli/vento-plugin-trim-self","commit_stats":null,"previous_names":["hedyhli/vento-plugin-trim-self"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/hedyhli/vento-plugin-trim-self","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hedyhli%2Fvento-plugin-trim-self","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hedyhli%2Fvento-plugin-trim-self/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hedyhli%2Fvento-plugin-trim-self/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hedyhli%2Fvento-plugin-trim-self/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hedyhli","download_url":"https://codeload.github.com/hedyhli/vento-plugin-trim-self/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hedyhli%2Fvento-plugin-trim-self/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32396781,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-28T19:38:08.556Z","status":"ssl_error","status_checked_at":"2026-04-28T19:37:55.688Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deno","plugin","vento"],"created_at":"2024-10-09T03:05:37.568Z","updated_at":"2026-04-28T20:02:02.911Z","avatar_url":"https://github.com/hedyhli.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Trim Self\n\n[![Deno tests](https://github.com/hedyhli/vento-plugin-trim-self/actions/workflows/deno.yml/badge.svg)](https://github.com/hedyhli/vento-plugin-trim-self/actions/workflows/deno.yml)\n![deno-coverage](https://img.shields.io/badge/Coverage-100%25-2ebb4e)\n\nRemove trailing newline and leading indent on tags that do not replace\nitself with content, **only if the tag appears on its own line**.\n\nSimilar to [autoTrim](https://vento.js.org/plugins/auto-trim/), but does not\ntrim aggressively. In effect, it makes tags such as `[/]function`, `[/]if`, and\nother tags that do not get replaced with content (such as `echo`), appear as\nthough they were not there.\n\nThis plugin exists to enable auto-trimming work as expected when vento is used\nfor file formats where whitespace is significant, such as markdown, unlike HTML.\n\n## How it works\n\nFor such tags that are on a **line of its own**, ie:\n- Has optional leading indents preceded directly by a newline, AND\n- Either EOF or a newline after it.\n\nThen, only these kind of whitespace are removed:\n- Spaces and tabs, preceded by a single newline on its left -- ie, indent --\n  replaced by a newline, in other words, dedented.\n- One trailing newline on this kind of tags, this single `\\n` OR `\\r\\n` is\n  removed;\n\n**No other kind of whitespace around such tags are removed**, unlike autoTrim.\n\nTable of contents:\n\n\u003c!-- mtoc-start --\u003e\n\n* [Example](#example)\n* [Why trim-self when we already have auto-trim?](#why-trim-self-when-we-already-have-auto-trim)\n* [Setup](#setup)\n  * [Vento example](#vento-example)\n  * [Lume example](#lume-example)\n* [Usage](#usage)\n* [TODO](#todo)\n\n\u003c!-- mtoc-end --\u003e\n\n## Example\n\nTemplate:\n```\n\u003cp\u003e\n  Text before.\n  {{ set name = \"world\" }}\n  Hello, {{ name }}!\n\u003c/p\u003e\n```\n\nWithout trim-self:\n```\n\u003cp\u003e\n  Text before\n__\n  Hello, world!\n\u003c/p\u003e\n```\n\nTrailing spaces represented as `_`.\n\nAfter trim-self:\n```\n\u003cp\u003e\n  Text before.\n  Hello, {{ name }}!\n\u003c/p\u003e\n```\n\nHere's the step-by-step transformation for the `{{ set ... }}` tag:\n\n\u003col\u003e\n\u003cli\u003e\n\n```\n\u003cp\u003e\n  Text before.\n  {{ set name = \"world\" }}\n  Hello, {{ name }}!\n\u003c/p\u003e\n```\n\n\u003c/li\u003e\n\u003cli\u003e\n\n```\n\u003cp\u003e\n  Text before.\n  {{ set name = \"world\" }}  Hello, {{ name }}!\n\u003c/p\u003e\n```\n\n\u003c/li\u003e\n\u003cli\u003e\n\n```\n\u003cp\u003e\n  Text before.\n{{ set name = \"world\" }}  Hello, {{ name }}!\n\u003c/p\u003e\n```\n\n\u003c/li\u003e\n\u003cli\u003e\n\nAfter vento's processing:\n```\n\u003cp\u003e\n  Text before.\n  Hello, {{ name }}!\n\u003c/p\u003e\n```\n\n```\n\u003cp\u003e\n  Text before.\n  Hello, world!\n\u003c/p\u003e\n```\n\n\u003c/li\u003e\n\u003c/ol\u003e\n\nCheck out the [tests](./trimSelf.test.ts) for self-documenting examples.\n\n\n## Why trim-self when we already have auto-trim?\n\nAuto-trim does a great job at doing what it's supposed to do, but both auto-trim\nand the built in trimming functionality (similar to Go templates), remove\nwhitespace too aggressively.\n\nFor instance, consider this template:\n\n```\nInline{{ if true }} test{{ /if }}\n- {{ if true }}List item.{{ else }}Other list item.{{ /if }}\nSome text after.\n```\n\nWith autoTrim, it would be transformed into:\n\n```\nInline test-List item.Some text after.\n```\n\nTrim-self does what you expect out of a plugin that will simply \"make template\ntags produce code such that it was as though they weren't there.\"\n\n```\nInline test\n- List item.\nSome text after.\n```\n\nFurthermore, `autoTrim` will remove trailing spaces followed by a newline, while\nthis may desirable **in general**, `trimSelf` does not do this because this\nfunctionality should be delegated to editors and tooling.\n\n## Setup\n\n### Vento example\n\n```ts\nimport trimSelf from \"https://deno.land/x/vento_plugin_trim_self/mod.ts\"\n\nenv.use(trimSelf());\n```\n\n### Lume example\n\n```js\n// _config.ts / _config.js\nimport lume from \"lume/mod.ts\";\nimport vento from \"lume/plugins/vento.ts\";\nimport trimSelf from \"https://deno.land/x/vento_plugin_trim_self/mod.ts\";\n\nconst site = lume();\nsite.use(vento({\n  plugins: [trimSelf()],\n  options: {},\n}))\n\nexport default site;\n```\n\n## Usage\n\nTrim-self does its job automatically.\n\n## TODO\n\nFilters are not yet supported:\n```vento\n{{ for item in list |\u003e myFilter }}\n\u003c!-- the newline after the above tag will not be trimmed --\u003e\n{{ /for }}\n```\n\nSupport filters, by binding them to the left most (but closest) tag. Or at least\nadd docs on how to workaround this, i.e., in Lume, use `site.data(\"myFilter\", fn)`\nrather than `site.filter(\"myFilter\", fn)` and use it as `myFilter(list)` instead.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhedyhli%2Fvento-plugin-trim-self","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhedyhli%2Fvento-plugin-trim-self","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhedyhli%2Fvento-plugin-trim-self/lists"}