teknologi-umum / graphene

Lighter Carbon alternative made with Shiki
MIT License
27 stars 10 forks source link

Double spaces on svg format #117

Open krowter opened 2 years ago

krowter commented 2 years ago

Choosing svg as the output format results in double spaces

Comparison Screenshot from 2022-06-25 17-47-24

PS I used the web version, havent tried sending a POST request

Edited (1 Oct 2023): Not reproducible anymore :/

My code at the time

function pascalsTriangle(size) {
  const result = [[1]];

  for (let i = 0; i < size; i++) {
    const row = [];

    for (let j = 0; j <= i + 1; j++) {
      row.push((result[i][j] ?? 0) + (result[i][j - 1] ?? 0));
    }

    result.push(row);
  }

  return result;
}

function formatTriangle(triangle) {
  const SPACE = '  ';
  const size = triangle.length;

  for (let rowIndex = 0; rowIndex < size; rowIndex++) {
    let row = '';
    const leftPadding = size - rowIndex;

    row += SPACE.repeat(leftPadding);
    row += triangle[rowIndex].map(num => num.toString().padStart(SPACE.length * 2)).join('');

    console.log(row);
  }
}

formatTriangle(pascalsTriangle(10));