Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function parseLines(str, idx) {
let ret = '';
while (idx < str.length && /[0-9\-.,]/.test(str[idx])) {
ret += str[idx];
idx++;
}
if (str[idx - 1] === ',') { // Put back trailing commas
idx--;
ret = ret.slice(0, -1);
}
const range = rangeParser.parse(ret);
if (range === undefined || range.length == 0) {
return { result: range, index: idx, error: `Could not parse ${ret}` };
}
if (_.every(range, num => num > 0)) {
return { result: range, index: idx };
}
return { result: range, index: idx, error: 'Negative line index' };
}
// styles seen using this current approach but that's probably ok. Fixing
// the flash will require changing the theming approach and is not worth it
// at this point.
useEffect(() => {
setMounted(true);
}, []);
const button = useRef(null);
let highlightLines = [];
let codeBlockTitle = '';
const prismTheme = usePrismTheme();
if (metastring && highlightLinesRangeRegex.test(metastring)) {
const highlightLinesRange = metastring.match(highlightLinesRangeRegex)[1];
highlightLines = rangeParser
.parse(highlightLinesRange)
.filter((n) => n > 0);
}
if (metastring && codeBlockTitleRegex.test(metastring)) {
codeBlockTitle = metastring
.match(codeBlockTitleRegex)[0]
.split('title=')[1]
.replace(/"+/g, '');
}
let language =
languageClassName && languageClassName.replace(/language-/, '');
if (!language && prism.defaultLanguage) {
language = prism.defaultLanguage;
},
files: this.files.map(file => ({
path: path.join(this.path, file.path),
length: file.length,
offset: file.offset
})),
length: this.length,
name: this.infoHash
})
)
this.files = this.files.map(file => new File(this, file))
// Select only specified files (BEP53) http://www.bittorrent.org/beps/bep_0053.html
if (this.so) {
const selectOnlyFiles = parseRange.parse(this.so)
this.files.forEach((v, i) => {
if (selectOnlyFiles.includes(i)) this.files[i].select(true)
})
} else {
// start off selecting the entire torrent with low priority
if (this.pieces.length !== 0) {
this.select(0, this.pieces.length - 1, false)
}
}
this._hashes = this.pieces
this.pieces = this.pieces.map((hash, i) => {
const pieceLength = (i === this.pieces.length - 1)
? this.lastPieceLength
break;
case "highlight-end":
range += `${blockStart}-${lineNumber - 1},`;
break;
default:
break;
}
lines.splice(index, 1);
} else {
// lines without directives are unchanged
index += 1;
}
}
highlightLines = rangeParser.parse(range);
code = lines.join("\n");
}
const handleCopyCode = () => {
window.getSelection().empty();
setShowCopied(true);
setTimeout(() => setShowCopied(false), 2000);
};
return (
break;
case 'highlight-end':
range += `${blockStart}-${lineNumber - 1},`;
break;
default:
break;
}
lines.splice(index, 1);
} else {
// lines without directives are unchanged
index += 1;
}
}
highlightLines = rangeParser.parse(range);
code = lines.join('\n');
}
const handleCopyCode = () => {
copy(code);
setShowCopied(true);
setTimeout(() => setShowCopied(false), 2000);
};
return (
function getHighlightLines(code) {
const res = code.match(/highlight\{(.+?)\}/);
return res ? rangeParser.parse(res[1]) : [];
}
setMounted(true);
}, []);
const target = useRef(null);
const button = useRef(null);
let highlightLines = [];
let codeBlockTitle = '';
const {isDarkTheme} = useThemeContext();
const lightModeTheme = prism.theme || defaultTheme;
const darkModeTheme = prism.darkTheme || lightModeTheme;
const prismTheme = isDarkTheme ? darkModeTheme : lightModeTheme;
if (metastring && highlightLinesRangeRegex.test(metastring)) {
const highlightLinesRange = metastring.match(highlightLinesRangeRegex)[1];
highlightLines = rangeParser.parse(highlightLinesRange).filter(n => n > 0);
}
if (metastring && codeBlockTitleRegex.test(metastring)) {
codeBlockTitle = metastring
.match(codeBlockTitleRegex)[0]
.split('title=')[1]
.replace(/"+/g, '');
}
useEffect(() => {
let clipboard;
if (button.current) {
clipboard = new Clipboard(button.current, {
target: () => target.current,
});
export default ({children, className: languageClassName, metastring}) => {
const {
siteConfig: {
themeConfig: {prism = {}},
},
} = useDocusaurusContext();
const [showCopied, setShowCopied] = useState(false);
const target = useRef(null);
const button = useRef(null);
let highlightLines = [];
if (metastring && highlightLinesRangeRegex.test(metastring)) {
const highlightLinesRange = metastring.match(highlightLinesRangeRegex)[1];
highlightLines = rangeParser.parse(highlightLinesRange).filter(n => n > 0);
}
useEffect(() => {
let clipboard;
if (button.current) {
clipboard = new Clipboard(button.current, {
target: () => target.current,
});
}
return () => {
if (clipboard) {
clipboard.destroy();
}
};
options.forEach(option => {
option = option.slice(0, -1);
if (rangeParser.parse(option).length > 0) {
highlightLines = rangeParser.parse(option).filter(n => n > 0);
}
});