Skip to content

Commit

Permalink
Merge pull request #773 from nature-of-code/dev/codesplit-comment
Browse files Browse the repository at this point in the history
Improve comment display and marks handling
  • Loading branch information
jasongao97 authored Feb 21, 2024
2 parents 02b4c47 + 678fe48 commit 9d41bee
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
31 changes: 21 additions & 10 deletions magicbook/plugins/codesplit.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,24 @@ Plugin.prototype = {
const regex = /\{(.+)\}/;
const match = regex.exec(line);
if (match) {
const values = match[1].trim().split(' ');
values.forEach((value) => {
if (value.charAt(0) === '#') pair.id = value.substring(1);
if (value.charAt(0) === '.') {
pair.className.push(value.substring(1));
}
if (value.charAt(0) === '!')
pair.maxLines = parseInt(value.substring(1));
});
// match !.#
const marks = match[1].match(/([!#.])([^!#.\s]+)/g);

if (marks) {
marks.forEach((mark) => {
switch (mark.charAt(0)) {
case '#':
pair.id = mark.substring(1);
break;
case '.':
pair.className.push(mark.substring(1));
break;
case '!':
pair.maxLines = parseInt(mark.substring(1));
break;
}
});
}
line = line.replace(regex, '');
}

Expand All @@ -94,7 +103,9 @@ Plugin.prototype = {

pairs.forEach((pair) => {
const code = pair.code.join('\n') + '\n';
const comments = pair.comment.map((str) => str.replace('//', '').trim());
const comments = pair.comment
.map((str) => str.replace('//', '').trim())
.filter((str) => !!str);
const className = pair.className.concat('pair');

// highlight the pair that has comment
Expand Down
5 changes: 4 additions & 1 deletion magicbook/stylesheets/components/codesplit.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
border-bottom-right-radius: 0;
border-bottom-left-radius: 0;
border-bottom: 1px dashed $color-gray-200 !important;
}

.pair:last-child::after {
position: absolute;
Expand Down Expand Up @@ -85,6 +84,10 @@
border-top: 1pt solid $color-gray-100;
}

&.highlight + .pair.continue {
border-top: initial;
}

.comment {
page-break-inside: avoid;
flex-grow: 1;
Expand Down

0 comments on commit 9d41bee

Please sign in to comment.