Skip to content

Commit

Permalink
fixed #1, fixed #8
Browse files Browse the repository at this point in the history
  • Loading branch information
pffy authored Aug 31, 2022
1 parent 7d60f44 commit cc3153d
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 13 deletions.
24 changes: 24 additions & 0 deletions src/fn.gs
Original file line number Diff line number Diff line change
Expand Up @@ -291,3 +291,27 @@ function addNamedRangeSelectHtml() {

return arr.join('\n');
}

// cleans Markdown in each table cell
function cleanText(str) {

// prevents "new column"
// all must go
str = str.replace(/\|/g, '|' );

// prevents list item
// first must go
str = str.replace(/^\*/, '*' );
str = str.replace(/^\-/, '+' );
str = str.replace(/^\+/, '−' );

// prevents headers
// first must go
str = str.replace(/^#/, '#' ); // hashtag

// prevents quote block
// first must go
str = str.replace(/^>/, '>' );

return str;
}
2 changes: 1 addition & 1 deletion src/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
<a href="https://a.pffy.dev/about/privacy">privacy</a>
&middot; <a href="https://a.pffy.dev/about/terms">terms</a>
&middot; <a href="https://a.pffy.dev/about/licenses">licenses</a>
&middot; <a href="https://m.pffy.dev/cotton-whats-new">version-8</a>
&middot; <a href="https://m.pffy.dev/cotton-whats-new">version-9</a>
</div>
65 changes: 53 additions & 12 deletions src/obj.gs
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,31 @@ function cotton (range) {
const valids = rng.getDataValidations();

// any data validation, including checkboxes
const hasValids = hasAnyValids(valids);
const hasValids = !valids.every(function(r){ // rows
return true === r.every(function(c){ // columns
return c === null;
});
});

// notes on cell input
const notes = rng.getNotes();

let noteCount = 0;
let noteItem = '';

const footnotes = [];

// any notes?
const hasNotes = !notes.every(function(r){ // rows
return true === r.every(function(c){ // columns
return c === "";
});
});

if(hasNotes) {
footnotes.push('\n\n### Notes');
}

// cell values
const values = rng.getValues();

Expand All @@ -77,12 +97,16 @@ function cotton (range) {
x = i - 1;

if(displayValues[x].every(isBlank)) {

arr = new Array(cols).fill('&nbsp;');
table.push(arr.join(pipe).trim());

if(i < 2) {
table.push(rowtwo);
}

continue;

} else {
arr = [];
}
Expand Down Expand Up @@ -113,13 +137,31 @@ function cotton (range) {
continue;
}

// sanitize Markdown table text
val = cleanText(val);

// process notes first
if(hasNotes && notes[x][y]) {
noteCount++;
noteItem = `<sup>${noteCount}</sup>`;
footnotes.push(`${noteItem} ${notes[x][y]}<br/>`);
}


// simply prints text check box for this cell
if(hasValids && valids[x][y] && isCheckbox(valids[x][y])) {
if(cell.isChecked()) {
arr.push('`[X]`');
val = '`[X]`';
arr.push();
} else {
arr.push('`[ ]`');
val = '`[ ]`';
}

if(hasNotes && notes[x][y]) {
val = val + noteItem;
}

arr.push(val); // checkbox cell complete
continue;
}

Expand All @@ -144,6 +186,10 @@ function cotton (range) {
// NOTE: should be after font styling
val = val.replace(/\n/g, '<br/>');

if(hasNotes && notes[x][y]) {
val = val + noteItem;
}

arr.push(val);
}

Expand All @@ -154,6 +200,10 @@ function cotton (range) {
}
}


// add footnotes below markdown table
table.push(footnotes.join('\n') + '\n');

// some inner functions

// returns true if row is hidden; otherwise, false.
Expand All @@ -180,15 +230,6 @@ function cotton (range) {
return false;
}

// returns true if any valid types detected; otherwise, false
function hasAnyValids(arr) {
return !arr.every(function(r){
return true === r.every(function(c){
return c === null;
});
});
}

// returns true if any checkboxes detected; otherwise, false
function isCheckbox(validation) {
return validation.getCriteriaType().toJSON() === 'CHECKBOX';
Expand Down

0 comments on commit cc3153d

Please sign in to comment.