dopetalk does not endorse any advertised product nor does it accept any liability for it's use or misuse


Our Discord Notification Server invitation link is https://discord.gg/jB2qmRrxyD

Author Topic: PDF BBCode Tag to Automatically Display All PDFs  (Read 176 times)

Offline Chip (OP)

  • Server Admin
  • Hero Member
  • *****
  • Administrator
  • *****
  • Join Date: Dec 2014
  • Location: Australia
  • Posts: 7285
  • Reputation Power: 0
  • Chip has hidden their reputation power
  • Gender: Male
  • Last Login:Today at 08:54:11 AM
  • Deeply Confused Learner
  • Profession: IT Engineer now retired
PDF BBCode Tag to Automatically Display All PDFs
« on: July 21, 2026, 09:00:11 PM »
Work in Progress For Simple Machines

Instructions yet to be given to Claude.ai:
---------------------------------------------
Build (read on) what we currently support now and then incrementally, perhaps at the end of every session, build a downloadable file that lists EACH and EVERY markdown we support and supply an example of its raw text -- and please don't forget any CSS if warranted.

In the end we will have a thorough and concise manual/handbook to both support and document ourmod's powerful capabilities -- this is to be world-standard breadth of rendering.


Implementing Mozilla's PDF Javascript Viewer by BBCode Tags

Written by Chipper (Andrew Egerszegi) with Claude.ai

Compatibility: SMF 2.0.x & SMF 2.1.x

Description and Notes

Rendered with a bundled, self-hosted copy of Mozilla's PDF.js viewer in an <iframe>.

* Three ways to use the tag:

   
   * [pdf]https://example.com/file.pdf[/pdf]
    - displays a locally stored pdf file in web root   

    * [pdf=attach-nn]x[/pdf]
    - displays the attachment (starts from 0)
 
    * [pdf=autodisplay]x[/pdf]
    - displays every PDF attached to this post automatically
   
   * [pdf=noautodisplay]x[/pdf]
    - stop the automatic display of all attached PDF files
   


Modifying the PDF Viewer defaults:

To set the scroll mode (`ScrollMode.PAGE = 3` — that's "one page at a time, scroll/navigate between them" (what you want, instead of continuous vertical which is `VERTICAL = 0`).

nano +4435 /var/www/html/Themes/default/pdfjs/web/viewer.mjs

Change `-1` → `3` (shown below)

Code: [Select]
  scrollModeOnLoad: {
    value: 3,
    kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  },

Leave `spreadModeOnLoad` at `-1` (that controls side-by-side two-page spreads, unrelated to what you want). Reload a PDF after saving and it should open one page at a time with prev/next navigation instead of the continuous scroll.

Testing:

Display by URL to its webroot filename


Display by attachment id


Display every attachment automatically
[pdf=autodisplay]x[/pdf]


« Last Edit: July 30, 2026, 03:12:08 AM by smfadmin »
friendly
0
funny
0
informative
0
agree
0
disagree
0
like
0
dislike
0
No reactions
No reactions
No reactions
No reactions
No reactions
No reactions
No reactions
Our Discord Server invitation link is https://discord.gg/jB2qmRrxyD

Offline smfadmin

  • SMF (internal) Site
  • Administrator
  • Sr. Member
  • *****
  • Join Date: Dec 2014
  • Location: Management
  • Posts: 574
  • Reputation Power: 0
  • smfadmin has hidden their reputation power
  • Last Login:Today at 06:18:00 AM
  • Supplied Install Member
Re: PDF BBCode Tag to Automatically Display All PDFs
« Reply #1 on: July 29, 2026, 09:56:29 AM »

Checkpoint: MD BBCode Mod — GFM Conformance Pass

Purpose: bring Andrew's SMF Markdown BBCode mod (MDParser.php/MDBBC.php) up to a level of GFM spec conformance good enough to satisfy SMF's lead dev, who recommended testing against the full GFM spec (https://github.github.com/gfm/) after reviewing the mod for possible official SMF inclusion.

Files / components

FileStatusUse it?
MDParser.php (this session's patched version, attached)Patched: emphasis rewrite, loose/tight lists, indented-code blank-line merging, link destination fixes, code span fix, bare-URL/www/email autolinkingYes — this is the current working version, supersedes the originally-uploaded copy
MDBBC.php (originally uploaded)Untouched this session — no changes were neededYes, unchanged
MD_SYNTAX_MANUAL.md (attached)Full table of every currently-supported syntax element + raw/rendered examples, generated from the actual current parserYes — hand this to anyone (including SM) who wants to see current scope
extract_spec.py (attached)One-time script: pulls cmark-gfm's test/spec.txt and converts it to spec.json (672 examples, tagged by section/extension)Only needed if spec.json (attached separately) is ever lost — otherwise skip straight to run_tests.php
spec.json (attached)Already-extracted output of extract_spec.py — the 672-example test suite itselfYes — drop it next to MDParser.php and run_tests.php, no re-fetch needed
run_tests.php (attached)Runs MDParser.php against every example in spec.json, writes results.jsonRe-run after every parser change
analyze.py (attached)Reads results.json, applies a "cosmetic-diff-tolerant" normalizer (strips our own CSS classes, rel= attribute, self-closing-tag style, tag-per-line formatting) to separate real bugs from harmless serialization differences; writes real_failures.json and prints per-section pass ratesRe-run after every run_tests.php run

Verified facts — don't re-check

  • The GFM spec's machine-readable test suite lives at test/spec.txt in github/cmark-gfm on GitHub (raw: raw.githubusercontent.com/github/cmark-gfm/master/test/spec.txt), in a literate format (fenced blocks marked `...`` example [extension-name] , input, a lone . line, expected HTML, closing fence). extract_spec.py parses this correctly — 672 examples extracted, matching the known canonical GFM spec size.
  • PHP is not preinstalled in this environment; apt-get install -y php-cli works (no sudo needed, container runs as root) and pulls PHP 8.3.
  • Raw pass rate (exact string match) is a bad metric here — many of the mod's own intentional additions (CSS classes md-code-block/md-table, the rel="noopener noreferrer nofollow" security hardening on links, HTML5-style non-self-closing tags) cosmetically differ from the reference renderer's output without being bugs. Always read the normalized pass rate from analyze.py, and treat real_failures.json (not raw results.json) as the list of genuine bugs.
  • Confirmed baseline at session start: 138/672 raw, 282/672 (42%) normalized.
  • Confirmed after this session's fixes: 200/672 raw, 396/672 (59%) normalized.
  • Confirmed ceiling: literal 672/672 is not a sensible goal. Reference-style links/link-reference-definitions and full raw-HTML-block parsing are deliberately out of scope (~100+ examples) — the latter because supporting it would conflict with the mod's "escape everything, selectively re-decode" security model, which the prior external security review specifically hardened. Realistic achievable ceiling is roughly 550–600/672 (~85-90%).
  • Confirmed via direct testing against the npm commonmark reference package: one spec example (__foo, __bar__, baz__) has an expected output in cmark-gfm's own spec.txt that disagrees with what the reference implementation's actual delimiter-stack algorithm produces (nested vs. flat <strong>). Traced this to the algorithm level, not a wasted rabbit hole — treat as a known, accepted gray area, do not re-derive.
  • Andrew's stated priority order (confirmed, his words): emphasis + list nesting first (highest-traffic, most complaint-prone), then links + blockquote laziness, then headings/tables (already solid), then fenced/indented code + thematic breaks/autolinks/escaping (lowest priority).
  • Andrew has separately built a syntax reference manual for the &#91;md&#93; tag on his own and confirmed it renders well — this may or may not be the same document as MD_SYNTAX_MANUAL.md above; worth asking rather than assuming they're the same artifact.
  • Forum BBC policy: all standard BBCode tags are disabled except [nobbc] (kept enabled/exempt as the literal-text escape hatch) and [md] itself. This is stated in MD_SYNTAX_MANUAL.md's header warning and in MDBBC.php's top doc-comment — check both stay in sync if the policy ever changes.

Open items (decisions, not blockers)

  • Base angle-bracket autolink (<scheme://...>) only recognizes http/https/ftp/ftps/mailto. CommonMark's actual rule allows any scheme matching [a-zA-Z][a-zA-Z0-9+.-]{1,31}:. Decision needed: is broadening this worth it for a forum (real schemes people might paste: irc://, magnet:, steam://), or is the current allowlist a deliberate security stance worth keeping as-is?
  • Link destinations don't yet balance parens ((foo(bar)) inside a bare URL) or do full percent-encoding of unsafe characters — only literal-space encoding is implemented. Decision needed: how much of this edge case is worth chasing given forum posts rarely paste raw unencoded URLs with parens.
  • Blockquote laziness (continuation lines without a leading >) is now fixed for the common case (paragraph continuation only, not headings/lists/fences/thematic breaks/indented code, and not after a blank line). Remaining edge case: laziness tracking inside an already-open non-paragraph block within a quote (e.g. an unclosed fence) isn't precise - low priority.
  • List "same list vs new list" rules fixed this session: a changed bullet character (-/*/+) or ordered delimiter style (. vs )) now correctly starts a new list; an ordered list can only interrupt a paragraph if it starts at 1.
  • Link destinations now do real percent-encoding (HTML entity decode, then percent-encode any byte outside the URL-safe set while preserving existing valid %XX sequences) and correctly balance parentheses via a recursive regex ([link](foo(and(bar))) works). Caution for future edits: adding a named recursive group inside an existing capturing group shifts the numeric index of every group after it — this caused a real regression this session (title text silently became a duplicate of the URL) until the shifted indices were corrected. Double-check group numbering with a quick preg_match test whenever the link/image regex structure changes again.
  • Link destinations still don't do full percent-encoding (backslash → %5C, HTML entities like &auml;%C3%A4, non-ASCII chars, quotes in a titleless destination) — only literal-space encoding is implemented. This is the largest remaining Links gap (roughly a dozen of the remaining ~53 failures).
  • Angle-bracket link destinations spanning a literal line break ([link](<foo\nbar>), which per spec should NOT be a valid link) aren't rejected, because paragraph-line-joining happens at the block level before this inline check ever sees the newline — a real but low-priority structural limitation.
  • Whether to reconcile/merge with Andrew's own separately-built syntax manual, or keep MD_SYNTAX_MANUAL.md as this session's independent version.

Next actual action

Run analyze.py's per-section breakdown on the current real_failures.json. Links is now largely down to reference-style-link failures (out of scope) plus a handful of exotic raw-HTML-mixed-with-brackets edge cases — List items (32/48) and Lists (13/26) are the next-best-value targets. Starting a fresh session should: install php-cli (apt-get install -y php-cli, no sudo needed), drop all six attached files in one directory, then run php run_tests.php && python3 analyze.py, and pick up from there.

« Last Edit: Yesterday at 12:19:07 PM by smfadmin »
friendly
0
funny
0
informative
0
agree
0
disagree
0
like
0
dislike
0
No reactions
No reactions
No reactions
No reactions
No reactions
No reactions
No reactions
measure twice, cut once

Offline smfadmin

  • SMF (internal) Site
  • Administrator
  • Sr. Member
  • *****
  • Join Date: Dec 2014
  • Location: Management
  • Posts: 574
  • Reputation Power: 0
  • smfadmin has hidden their reputation power
  • Last Login:Today at 06:18:00 AM
  • Supplied Install Member
(No subject)
« Reply #2 on: July 30, 2026, 11:08:13 PM »
Topic bumped
friendly
0
funny
0
informative
0
agree
0
disagree
0
like
0
dislike
0
No reactions
No reactions
No reactions
No reactions
No reactions
No reactions
No reactions
measure twice, cut once

Tags:
 


dopetalk does not endorse any advertised product nor does it accept any liability for it's use or misuse





TERMS AND CONDITIONS

In no event will d&u or any person involved in creating, producing, or distributing site information be liable for any direct, indirect, incidental, punitive, special or consequential damages arising out of the use of or inability to use d&u. You agree to indemnify and hold harmless d&u, its domain founders, sponsors, maintainers, server administrators, volunteers and contributors from and against all liability, claims, damages, costs and expenses, including legal fees, that arise directly or indirectly from the use of any part of the d&u site.


TO USE THIS WEBSITE YOU MUST AGREE TO THE TERMS AND CONDITIONS ABOVE


Founded December 2014
SimplePortal 2.3.6 © 2008-2014, SimplePortal