I’m running this php script on a schedule to generate a page of all highlighted passages in my vault. Note that it assumes your highlights do not span multiple paragraphs (and I am on Windows). Hope it sparks some ideas of the possibilities.
<?php
$dir = "C:\Users\CHANGE_THIS\Dropbox\info"; // Set to your vault location
$files = getMarkdownFiles();
$md = "# Highlights demo\n";
foreach($files as $file){
$content = file_get_contents($file);
$lines = explode("\n",$content);
foreach($lines as $line){
if(strpos($line,'==') !== false){
$topic = str_replace($dir.'/','',$file);
$topic = str_replace('.md','',$topic);
$md .= "## [[{$topic}]]\n";
$md .= get_string_between($line,'==','==');
$md .= "\n";
}
}
}
file_put_contents($dir . "/Highlights demo.md",$md);
function getMarkdownFiles()
{
global $dir;
$fileList = glob($dir . '/*.md');
return $fileList;
}
function get_string_between($string, $start, $end){
$string = ' ' . $string;
$ini = strpos($string, $start);
if ($ini == 0) return '';
$ini += strlen($start);
$len = strpos($string, $end, $ini) - $ini;
return substr($string, $ini, $len);
}