Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2019-10-28 18:06:48

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,909
Website

[solved] pre (in relation to escape="" attribute in txp:body)

I want to show these lines as code, just like they appear here:

<h1 class="preface">Preface</h1>

<hr class="asterism" />

<header id="chap1" class="chapter">
  <h1>Chapter 1</h1>
  <h2>[Chapter Title]</h2>
</header>

<h3>[Chapter subsection]</h3>

etc

<h1 class="postface">Postface</h1>

And I have this CSS, which is, in fact, based on this forum’s styles:

pre,
pre code {word-wrap:normal;}

pre {
	line-height:1.1;
	display:block;
	margin:1em 0;
}

pre code {
	word-break:normal;
	white-space:pre;
	word-spacing:normal;
	hyphens:none;
}

I think white-space:pre; is the key. But all I get is a long, single line of non-wrapping text. No line breaks or blank lines are retained.

If I change white-space:pre; to white-space:pre-wrap;, the single line wraps, but still no line breaks or blank lines as appearing above.

What am I missing? I’m baffled.

Offline

#2 2019-10-28 19:30:08

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,379
Website GitHub Mastodon

Re: [solved] pre (in relation to escape="" attribute in txp:body)

Have you tried the code tag?

<pre>
  <code>
    p { color: red; }
    body { background-color: #eee; }
  </code>
</pre>

Also see the thread: Syntax highlighting in articles

Offline

#3 2019-10-28 19:54:08

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,909
Website

Re: [solved] pre (in relation to escape="" attribute in txp:body)

Yes, sorry, I should have specified. I’m using Textile’s bc.., which renders code wrapped in pre. Just like I’m using it in this forum. But the behaviour as described exists.

Offline

#4 2019-10-28 22:19:29

phiw13
Plugin Author
From: Japan
Registered: 2004-02-27
Posts: 3,190
Website

Re: [solved] pre (in relation to escape="" attribute in txp:body)

  • Do you have a page that shows the issue ?
  • Do you use some script that minifies the HTML (removes unnecessary white-space and line-breaks in the HTML source) ?

The latter is probably the more likely explanation for the behaviour you see with white-space:pre / white-space:pre-wrap.


Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern

Offline

#5 2019-10-29 12:49:14

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,909
Website

Re: [solved] pre (in relation to escape="" attribute in txp:body)

phiw13 wrote #319858:

Do you have a page that shows the issue ?

It’s local dev for Full Point. Not live. I’m just creating a ‘draft article template’ with a bunch of article sections and snippets already added and described, so it’s easy use what I need, or remove what I don’t, each time I start a new article. I don’t have any actual articles yet that uses code blocks, and I don’t suspect I’ll ever have many, but I’m just getting a module for it designed in case.

That said, it’s the exact same install as what’s online, just the CSS difference noted above, added to articles.css.

Do you use some script that minifies the HTML (removes unnecessary white-space and line-breaks in the HTML source) ? The latter is probably the more likely explanation for the behaviour you see with white-space:pre / white-space:pre-wrap.

I don’t use any plugins for that, and I’ve not added any such scripts to my site. But here’s my diagnostics…

Textpattern version: 4.7.3 (7c46d1f4c8ac79e62a7d5e54a9ddac53)
Last update: 2019-03-11 07:38:57/2019-02-25 22:22:30
Textpattern path: __TXP-ROOT/textpattern
Article URL pattern: title_only
Production status: live
Temporary directory path: __TXP-ROOT/textpattern/tmp
PHP version: 7.2.9
GD Graphics Library: bundled (2.1.0 compatible); Supported formats: GIF, JPEG, PNG.
Server timezone: Europe/Zurich
Server local time: 2019-10-29 13:32:35
Daylight Saving Time enabled?: 0
Automatically adjust Daylight Saving Time setting?: 0
Time zone (GMT offset in seconds): Europe/Paris (+0)
MySQL: 5.7.13 (Homebrew) 
Database server time: 2019-10-29 13:32:35
Database server time offset: 0 s
Database server timezone: SYSTEM
Database session timezone: SYSTEM
Locale: en_GB.UTF-8
Site / Admin language: en / en
Web server: Apache/2.4.33 (Unix) PHP/7.2.9
Apache version: Apache/2.4.33 (Unix) PHP/7.2.9
PHP server API: apache2handler
RFC 2616 headers: 
Server OS: Darwin 17.7.0
Admin-side theme: hive 4.7.3
Active plugins: 
	rvm_maintenance-0.5
	smd_article_stats-0.40 (modified)
	smd_where_used-0.30
	soo_toc-0.1.5

.htaccess file contents: 
------------------------
# ----------------------------------------------------------------------
#   A] CROSS-ORIGIN
# ----------------------------------------------------------------------

# A.1] Cross-Origin Requests

# <IfModule mod_headers.c>
#     Header set Access-Control-Allow-Origin "*"
# </IfModule>

# A.2] Cross-Origin Images

#<IfModule mod_setenvif.c>
#    <IfModule mod_headers.c>
#        <FilesMatch "\.(bmp|cur|gif|ico|jpe?g|png|svgz?|webp)$">
#            SetEnvIf Origin ":" IS_CORS
#            Header set Access-Control-Allow-Origin "*" env=IS_CORS
#        </FilesMatch>
#    </IfModule>
#</IfModule>

# A.3] Cross-Origin Fonts

<IfModule mod_headers.c>
    <FilesMatch "\.(eot|otf|tt[cf]|woff2?)$">
        Header set Access-Control-Allow-Origin "*"
    </FilesMatch>
</IfModule>

# ----------------------------------------------------------------------
# B] ERRORS
# ----------------------------------------------------------------------
# B.1] Custom Error Messages/Pages

# ErrorDocument 404 /404.html
# ErrorDocument 403 default

# ----------------------------------------------------------------------
# C] MEDIA TYPES & CHARACTER ENCODINGS
# ----------------------------------------------------------------------

# C.1] Media Types

<IfModule mod_mime.c>
	# Media files
	# Used by Textpattern too.
	AddType image/svg+xml  svg svgz

	# Web fonts
	AddType font/woff                      woff
	AddType font/woff2                     woff2
	AddType font/ttf                       ttf
	AddType font/collection                ttc
	AddType font/otf                       otf

	# Other
	AddType text/markdown markdown md		
</IfModule>

# C.2] Character Encodings

AddDefaultCharset utf-8

# C.3]  Type 'charset' to 'UTF-8'

<IfModule mod_mime.c>
	AddCharset utf-8 .appcache \
                     .bbaw \
                     .css \
                     .htc \
                     .ics \
                     .js \
                     .json \
                     .manifest \
                     .map \
                     .markdown \
                     .md \
                     .mjs \
                     .topojson \
                     .vtt \
                     .vcard \
                     .vcf \
                     .webmanifest \
                     .xloc
</IfModule>

# ----------------------------------------------------------------------
# D] REWRITES
# ----------------------------------------------------------------------

# D.1] Textpattern CMS

<IfModule mod_rewrite.c>
	RewriteEngine On
	#RewriteBase /relative/web/path/
	#Options +FollowSymLinks

	RewriteCond %{REQUEST_FILENAME} -f [OR]
	RewriteCond %{REQUEST_FILENAME} -d
	RewriteRule ^(.+) - [PT,L]

	RewriteCond %{REQUEST_URI} !=/favicon.ico
	RewriteRule ^(.*) index.php

	RewriteCond %{HTTP:Authorization}  !^$
	RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization}]		
</IfModule>

# D.2] Forcing `No WWW`

<IfModule mod_rewrite.c>
	RewriteEngine On
	RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
	RewriteRule ^(.*)$ http://%1/$1 [R=301,L]	
</IfModule>

# D.3] Forcing `https://`

# This needs commented out on local. Uncomment when live!

#<IfModule mod_rewrite.c>
	#RewriteEngine On
	#RewriteCond %{HTTPS} !=on
	#RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
#</IfModule>

# D.4] Block Access to Hidden Files/Directories

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_URI} "!(^|/)\.well-known/([^./]+./?)+$" [NC]
    RewriteCond %{SCRIPT_FILENAME} -d [OR]
    RewriteCond %{SCRIPT_FILENAME} -f
    RewriteRule "(^|/)\." - [F]
</IfModule>

# D.5] Block Bad Robots

# See end of this file!

# ----------------------------------------------------------------------
# E] SECURITY
# ----------------------------------------------------------------------

# E.1] Clickjacking                                                       |

<IfModule mod_headers.c>
     Header set X-Frame-Options "DENY" "expr=%{CONTENT_TYPE} =~ m#text/html#i"
</IfModule>

# E.2] File Access

#DirectoryIndex index.php index.html

# E.3] Block Access to Directories w/o Default file

<IfModule mod_autoindex.c>
    Options -Indexes
</IfModule>

# E.4] Block Access to Files of Sensitive Nature

<IfModule mod_authz_core.c>
    <FilesMatch "(^#.*#|\.(bak|conf|dist|fla|in[ci]|log|orig|psd|sh|sql|sw[op])|~)$">
        Require all denied
    </FilesMatch>
</IfModule>

# E.5] Reducing Mime Type Security Risks

<IfModule mod_headers.c>
    Header set X-Content-Type-Options "nosniff"
</IfModule>

# E.6] Reflected Cross-Site Scripting (XSS) attacks

<IfModule mod_headers.c>
    Header set X-XSS-Protection "1; mode=block" "expr=%{CONTENT_TYPE} =~ m#text/html#i"
</IfModule>

# E.7] ETags

<IfModule mod_headers.c>
    Header unset ETag
</IfModule>

FileETag None

# E.8] Server-side Technology Information

<IfModule mod_headers.c>
    Header unset X-Powered-By
</IfModule>

# E.9] Server Software Information

ServerSignature Off

# ----------------------------------------------------------------------
# F] WEB PERFORMANCE
# ----------------------------------------------------------------------

<IfModule mod_deflate.c>

  # F.1] Force compression for mangled `Accept-Encoding` request headers.

  <IfModule mod_setenvif.c>
    <IfModule mod_headers.c>
      SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
      RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
    </IfModule>
  </IfModule>

  # F.2] Compress all output labeled with one of the following media types.

  <IfModule mod_filter.c>
    AddOutputFilterByType DEFLATE "application/atom+xml" \
                                  "application/javascript" \
                                  "application/json" \
                                  "application/ld+json" \
                                  "application/manifest+json" \
                                  "application/rdf+xml" \
                                  "application/rss+xml" \
                                  "application/schema+json" \
                                  "application/geo+json" \
                                  "application/vnd.ms-fontobject" \
                                  "application/wasm" \
                                  "application/x-font-ttf" \
                                  "application/x-javascript" \
                                  "application/x-web-app-manifest+json" \
                                  "application/xhtml+xml" \
                                  "application/xml" \
                                  "font/eot" \
                                  "font/opentype" \
                                  "font/otf" \
                                  "image/bmp" \
                                  "image/svg+xml" \
                                  "image/vnd.microsoft.icon" \
                                  "text/cache-manifest" \
                                  "text/calendar" \
                                  "text/css" \
                                  "text/html" \
                                  "text/javascript" \
                                  "text/plain" \
                                  "text/markdown" \
                                  "text/vcard" \
                                  "text/vnd.rim.location.xloc" \
                                  "text/vtt" \
                                  "text/x-component" \
                                  "text/x-cross-domain-policy" \
                                  "text/xml"

  </IfModule>

  # F.3] Force Apache to serve file types w/ appropriate `Content-Encoding` response header.

  <IfModule mod_mime.c>
		 AddEncoding gzip       svgz
  </IfModule>

</IfModule>

# ----------------------------------------------------------------------
# G] BLOCK BAD ROBOTS
# ----------------------------------------------------------------------
# Add the following 3 lines after every 500 bot names:
#  [NC,OR]
#  #500 new rule
#  RewriteCond %{HTTP_USER_AGENT} \

RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} \
. . .
a long-ass list of bots being blocked
. . .
 [NC]
RewriteRule .* - [F]
#bad bots end
------------------------

The only thing that looked possibly relevant to this mod-rewrite neophyte is section ‘F’ on web performance. I removed the entire section (the three modules there), but it didn’t change anything on a refresh, so I put them back.

Offline

#6 2019-10-29 13:23:03

phiw13
Plugin Author
From: Japan
Registered: 2004-02-27
Posts: 3,190
Website

Re: [solved] pre (in relation to escape="" attribute in txp:body)

Hmmmm. :~(

What does the raw source code looks like in Firefox (cmd U) or Safari (cmd-option U) ?


Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern

Offline

#7 2019-10-29 14:39:27

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,909
Website

Re: [solved] pre (in relation to escape="" attribute in txp:body)

Thanks for that push. Found the cause.

I was seeing all block elements corresponding to the Body field all in a single line (a very long line). That seemed odd.

A look in the corresponding form and I happened to spy this: <txp:body escape="trim, tidy" />.

I can’t remember why I put escape="trim, tidy" in the tag — I think I saw something mentioned about it in another thread somewhere quite a while back — but removing that returns pre behaviour as expected. And the page source view also returns as expected now.

So why would one want to use the escape attribute in the body? I’ll leave it out, but just wondering what the value could be, and if that suggests a bug in this case. Beats me.

Offline

#8 2019-10-29 16:58:08

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,379
Website GitHub Mastodon

Re: [solved] pre (in relation to escape="" attribute in txp:body)

jayrope wrote #311341:

The tidy option also works for bodies? That would be … congenial.

Bloke wrote #311353:

The escape attribute is global for all tags, so yes, any tag can benefit. Even plugins, as long as they haven’t overridden the core functionality.

Offline

#9 2019-10-29 22:25:34

phiw13
Plugin Author
From: Japan
Registered: 2004-02-27
Posts: 3,190
Website

Re: [solved] pre (in relation to escape="" attribute in txp:body)

Destry wrote #319863:

Thanks for that push. Found the cause.

I was seeing all block elements corresponding to the Body field all in a single line (a very long line). That seemed odd.

:-).

A look in the corresponding form and I happened to spy this: <txp:body escape="trim, tidy" />.

Yeah the trim value did exactly what it is designed to do: remove any redundant white-space. In this case it made a mess of your expected / desired display for the <pre /> element though – because all the line-breaks were gone.

So why would one want to use the escape attribute in the body? I’ll leave it out, but just wondering what the value could be, and if that suggests a bug in this case. Beats me.

Nothing wrong with being able to use the escape attribute there. And I do not see any bugs based on the tidbits of info you provide. It is a wee bit dangerous in a heavy-duty sledgehammer way to use the escape attribute there, though.


Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern

Offline

#10 2019-10-29 23:36:20

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,447
Website GitHub

Re: [solved] pre (in relation to escape="" attribute in txp:body)

phiw13 wrote #319868:

It is a wee bit dangerous in a heavy-duty sledgehammer way to use the escape attribute there, though.

Generally, yes. Using trim especially is perhaps ill-advised, but if you wanted to, for example, strip out any unwanted tags that an author may have used inline, escape could be mighty handy as a filter.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#11 2019-10-30 07:13:18

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,726
Website

Re: [solved] pre (in relation to escape="" attribute in txp:body)

Bloke wrote #319869:

Generally, yes. Using trim especially is perhaps ill-advised … or does it act on every block-level tag in txp:body?

P. Why trim? I thought that only acted on the outer limits of a string… Or does it act on every block-level HTML tag within the body?

I would have thought that tidy and especially tags have a more dramatic effect. Have I misunderstood that all this time?


TXP Builders – finely-crafted code, design and txp

Offline

#12 2019-10-30 07:57:06

phiw13
Plugin Author
From: Japan
Registered: 2004-02-27
Posts: 3,190
Website

Re: [solved] pre (in relation to escape="" attribute in txp:body)

Bloke wrote #319869:

Generally, yes. Using trim especially is perhaps ill-advised, but if you wanted to, for example, strip out any unwanted tags that an author may have used inline, escape could be mighty handy as a filter.

There are certainly use cases (you mention a good one!) for applying the escape attribute to such a high level, all encompassing container tag as @<txp:body />. But it requires serious thought to use.


Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern

Offline

Board footer

Powered by FluxBB