New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Boldening text of single-line items fixes #86
Comments
|
I immediately found another one. ProPublica has multiple paragraph titleless items. With the new approach we now bolden all the text and there's a lot of it. The boldening code has to look for |
function boldenTitlelessText (theText) { //12/15/23 by DW
const maxCharsInBold = Infinity; //disable feature
function bolden (s) {
return ("<b>" + s + "</b>");
}
function notWordChar (ch) {
if (isAlpha (ch)) {
return (false);
}
if (isNumeric (ch)) {
return (false);
}
return (true);
}
if (false) {//(theText.length <= maxCharsInBold) {
return (bolden (theText));
}
else {
function scanPastMarkup (theText, callback) {
var ix = 0, flInElement = false, ct = 0, watchthis = "";
function movePastRightAngleBracket () {
ix points to first char after <
we return with it pointing to the next char after the >
while (true) {
if (ix > (theText.length - 1)) {
break;
}
if (theText [ix++] == ">") {
break;
}
}
}
while (true) {
if (ix > (theText.length - 1)) { //we've run out of chars
break;
}
var ch = theText [ix++];
if (ch == "<") {
movePastRightAngleBracket ();
}
else {
if (!callback (ix, ++ct)) {
break;
}
}
watchthis = stringMid (theText, 1, ix + 1);
console.log (watchthis);
}
return (stringMid (theText, 1, ix));
}
function scanPastMarkup (theText, callback) {
var ix = 0, flInElement = false, ct = 0, watchthis = "";
while (true) {
if (ix > (theText.length - 1)) { //we've run out of chars
break;
}
var ch = theText [ix++];
if (ch == "<") {
flInElement = true;
}
else {
if ((ch == ">") && flInElement) {
flInElement = false;
}
else {
if (!callback (ix, ++ct)) {
break;
}
if (++ct >= ctChars) {
break;
}
}
}
watchthis = stringMid (theText, 1, ix + 1);
console.log (watchthis);
}
return (stringMid (theText, 1, ix));
}
var firstPart = scanPastMarkup (theText, function (ix, ct) { //get the first maxCharsInBold non-markup chars
if (ct >= maxCharsInBold) { //stop the scan
return (false);
}
else {
return (true); //continue
}
});
var flDone = false;
scanPastMarkup (firstPart, function (ix, ct) { //scan forward to find end of sentence, stop there
if ((firstPart [ix] == " ") && (firstPart [ix - 1] == ".")) {
firstPart = stringMid (firstPart, 1, ix);
flDone = true;
return (false);
}
else {
return (true);
}
});
if (!flDone) { //scan back from the end for the first non-word char, a space, punctuation, >
for (var i = firstPart.length - 1; i >= 0; i--) {
ch = firstPart [i];
if (notWordChar (ch)) {
firstPart = stringMid (firstPart, 1, i);
break;
}
}
}
}
const newText = bolden (firstPart) + theText.slice (firstPart.length);
return (newText);
} |
|
Fixed a huge bug in today's fix, so now it works a lot better. ;-) |
|
I'm keeping my eye out for unexpected issues. I found one before lunch with non-markdown feeds, but by the time I got back from lunch and started writing it up, you seemed to have already noticed and fixed it. |
|
That said, this is bolding the first line in every paragraph, not just every post, which may be unintended. This feed does not use markdown. XML for the single item above: |
|
Chuck, thanks for the report. There’s a more direct way to see the actual text that is being processed by the algorithm, if you click the |
|
BTW, there was a serious error in the corrected version of the code, so I have to try again. Will report. |
|
I decided to rewrite the code. As I'm working through it, I had an idea.
If it doesn't make it through the parser, send it back with no bold text. Any thoughts?? Worth a try? |
|
About the huge problem, I was able to make it so that That was in addition to fixing the big problem. So at this point I believe this feature "works." If more issues show up I believe they will be smaller weird edge cases, and if they're impossible to deal with another item can be opened at that time. |





In news timelines (aka rivers) we bolden the first sentence of a titleless item.
This feature went in on July 7. It would scan through the text of the headline, counting characters until it hit the end of a sentence or the 50th character and bolden all the text up to that point.
It would also have to deal with links and styling and whatever can be produced by markdown.
The problems would often appear with text generated from markdown, such as the text in John Spurlock's Bluesky feeds. If the magic 50th character showed up inside the text of an anchor element, usually you'd see a glitch of some kind.
It's been on my list for a long time, something to look at and finally I had the time.
The quick solution is to not have a character limit. As long as we haven't reached the end of a sentence, keep going. It didn't make sense as a reader when the ending would happen in the middle of the first sentence.
So I made the change, and it seems to help a lot.
Anyway, if you see glitchiness, the best thing is to post the text of the markdown the item was rendered from and if it's helpful include a screen shot.
The text was updated successfully, but these errors were encountered: