• I’m interesting in finding a way to make the code a WordPress site produces indented. I’ve considered writing the posts in a text editor and pasting the code in the textbox on the write post page.

    I’ve also tried to think of a plugin that would somehow modify wpautop to place four or five \t tabs before each paragraph opening tag. Any ideas how to do this?

    Example:

    <html>
    	<head>
    		<title>An Indented Source</title>
    	</head>
    	<body>
    		<h1>An Indented Source</h1>
    			<hr>
    			<div class="post">
    				<p>An indented paragraph within the_content().</p>
    			</div>
    	</body>
    </html>

Viewing 15 replies - 1 through 15 (of 15 total)
  • stvwlf

    (@stvwlf)

    If you are talking about indenting the first line of a paragraph, there is a way to easily do that using CSS.

    text-indent: 20px

    add it into your stylesheet. On most themes this will do it:
    #content p { text-indent: 20px }

    If you are talking about indenting every line of every paragraph, you can just increase the margin or padding on the container in which the post content appears. Then everything will appear indented.

    Thread Starter Jonathan Landrum

    (@jonlandrum)

    No, this has nothing to do with CSS. In fact, it has nothing to do with display at all. In the code above, I showed a sample HTML source. What I am trying to accomplish is “pretty-printed” code.

    There are functions to do this for PHP code, but how about the HTML it produces?

    Thread Starter Jonathan Landrum

    (@jonlandrum)

    There should be a way to edit wpautop to do this automatically.

    I once tried editing it to replace \n\n with </p>\n\t\t\t\t<p>. But it didn’t work. But shouldn’t that do it? Or am I doing something wrong?

    whooami

    (@whooami)

    .. and I thought I was anal ??

    Im sorry, I just couldnt resist.

    I went on a coding tangent until my my wp_head stuff was EXACTLY how I wanted it, so I really do understand the inclination.

    Thread Starter Jonathan Landrum

    (@jonlandrum)

    :~] I’ve always known you were anal, whoo. You were actually the first one to make *me* that way!

    So, can you think of any way I can achieve this?

    whooami

    (@whooami)

    OMG!! Youre blaming me??!!!

    hahahahah!! ?? I so love that ??

    I will have to think about that. I know on this most recent site I set up, I thought about toying with that, and scrapped it all together.

    Have you discovered that messing with the actual core code was not doable, because of upgrades, or just because it was unrealistic? Assuming you decided that, of course.

    Thread Starter Jonathan Landrum

    (@jonlandrum)

    Both. Since I’ve gotten my source via Subversion, and since Cron updates it every night, it would only be a matter of time before my hack disappeared.

    Thread Starter Jonathan Landrum

    (@jonlandrum)

    I could disable wpautop in a plugin, and after that function add the above code.

    I saw a fellow once whose source was simply gorgeous. Each paragraph was indented, no doubt, but each line broke after a certain number of characters, and the wrapped lines were indented, plus three spaces:

    ...
    	<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
    	   Etiam adipiscing, tellus sed consequat euismod, felis turpis
    	   tristique magna, vel placerat sem arcu eget lorem. Aliquam
    	   aliquet, sapien a tincidunt vulputate, mauris ligula sagittis
    	   tortor, sed egestas ante est vitae velit. Etiam pharetra.
    	   Pellentesque mattis, tortor sed congue consequat, neque enim
    	   ornare tellus, quis dapibus nisl nisi nec risus. Ut eget
    	   erat. Proin lacinia nunc at enim. Vivamus adipiscing
    	   fringilla metus. Mauris hendrerit. In rhoncus metus sed
    	   velit. Praesent diam diam, varius eu, egestas pharetra,
    	   euismod id, sem.</p>
    	<p>Curabitur dapibus. Mauris tincidunt mollis lacus. Ut ac
    	   justo. Phasellus faucibus diam non dui. Vivamus ut est. Nam
    	   et risus sit amet metus aliquam pharetra. Vivamus
    	   sollicitudin mauris at nisl. Sed tincidunt sollicitudin est.
    	   Proin pharetra. Donec euismod gravida est. Maecenas a sem.
    	   Aliquam erat volutpat. Praesent nibh. Aenean nisl tortor,
    	   porttitor sed, malesuada sit amet, dictum eget, lectus. Donec
    	   laoreet ante quis metus.</p>

    That is what I really would like to get to.

    Edit: Bah! Even here, with code marked up as such, it’s an un-attainable goal!

    Edit 2: It doesn’t like spaces after the code mark.

    whooami

    (@whooami)

    Bah!

    I wish my roommate were so inclined — maybe he would sweep once in a great while

    Thread Starter Jonathan Landrum

    (@jonlandrum)

    wp-includes/classes.php has some interesting code beginning at line 498:

    $indent = str_repeat("\t", $depth);

    $depth being a function previously defined.

    Thread Starter Jonathan Landrum

    (@jonlandrum)

    How about:

    remove_filter ('the_content', 'wpautop');
    remove_filter ('the_excerpt', 'wpautop');
    
    $prettyPrint = str_replace("\n\n", "</p>\n\t\t\t\t<p>", $prettyPrint);
    
    add_filter ('the_content', 'prettyPrint');
    add_filter ('the_excerpt', 'prettyPrint');
    Thread Starter Jonathan Landrum

    (@jonlandrum)

    This doesn’t work, but it’s where I’m at:

    <?php
    
    $t = str_repeat('\t', 4);
    $lineWidth = 75;
    $n = $n . PHP_EOL;
    $space = $space . '   ';
    
    function prettyPrint($code) {
    
    	// Don't Reformat Between Pre Tags
    	if (eregi('<%pre%[^>]*>(.*?)</%pre%>', $code)) {
    		return;
    	}
    
    	// Blockquote Formatting
    	if (eregi($n . $n . '<%blockquote%(.*?)>', $code)) {
    		$code = preg_replace($n . $n . '<%blockquote%(.*?)>', '</p>' . $n . $t . '<blockquote $1>', $code);
    	}
    
    	// Paragraph Formatting
    	if (eregi($n . $n, $code)) {
    		$code = str_replace($n . $n, '</p>' . $n . $t . '<p>', $code);
    	}
    
    	// Line Break Formatting
    	if (eregi($n, $code)) {
    		$code = str_replace($n, '<br />' . $n . $t . $space, $code);
    	}
    
    	return $code;
    }
    
    remove_filter ('comment_text', 'wpautop');
    remove_filter ('the_content', 'wpautop');
    remove_filter ('the_excerpt', 'wpautop');
    
    add_filter ('comment_text', 'prettyPrint', 10);
    add_filter ('the_content', 'prettyPrint', 10);
    add_filter ('the_excerpt', 'prettyPrint', 10);
    ?>

    Thread Starter Jonathan Landrum

    (@jonlandrum)

    Perhaps I should declare the variables global.

    Did you fix it at last? Code is poetry…

    Thread Starter Jonathan Landrum

    (@jonlandrum)

    No, it never worked. I’m still searching for a way.

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘How to modify wpautop to add tabs before <p>’ is closed to new replies.