#!/usr/bin/env node

// Copyright 2014-2025 Jesper Larsson
//
// This file is part of Klipspringer, <https://klipspringer.avadeaux.net/>
//
// Klipspringer is free software: you can redistribute it and/or modify it under the terms of the
// GNU General Public License as published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// Klipspringer is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
// even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License along with Klipspringer. If
// not, see <https://www.gnu.org/licenses/>.

import * as readline from 'readline';

const target = process.argv[2];
const values = process.argv[3] ? JSON.parse(process.argv[3]) : { };

const rl = readline.createInterface({ input: process.stdin });
const stack = [];
let gobble = false;

for await (const line of rl) {
    const beg = line.match(/^\s*#\s*{{\s*only\s*(?:\(\s*([a-zA-Z_.]+)\s*\))?\s*([^(){}]*?)\s*}}\s*$/);
    if (beg) {
        stack.push(gobble);
        if (!gobble && !beg[2].includes(target)) {
            const replacement = values[beg[1]];
            if (replacement) { console.log(replacement) }
            gobble = true;
        }
    } else if (line.match(/^\s*#\s*{{\s*endonly\s*}}\s*$/)) {
        if (stack.length === 0) {
            console.error("Too many {{ endonly }}");
            process.exit(65);
        }
        gobble = stack.pop();
    } else if (!gobble) {
        console.log(line);
    }
}
if (stack.length > 0) {
    console.error("Unmatched {{ only }}");
    process.exit(65);
}

Version: v4.3.2.2 (2026-05-16T17:03:34+02:00)
Raw file
Source code overview
Klipspringer home