wp-syntax(geshi)使用小技巧

2008年10月12日 21:21  |  分类:wordpress

一般情况下,wp-syntax会自动将代码中的tab设置成8,这对于紧张的网页来说是很浪费的,解决的方法有两种:一种是修改geshi的源代码,另一种是用文本编辑器将代码中的tab转换成空格。

By default, Geshi wraps code blocks in pre tags (header_type = GESHI_HEADER_PRE). In this mode, tabs are not substituted for spaces, so the browser is displaying the tab directly and the width is browser dependent. Personally, I avoid tabs like the plague in my source code, but if you’re not like me, you can try setting the header type to GESHI_HEADER_DIV. For example: http://wordpress.org/support/topic/138861

请对比下面两种效果:

一、tab未转换之前
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php get_header(); ?>
<div id="wrapper">
	<div id="content">
	<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
		<div class="navigation">
			<div class="alignleft"><?php previous_post_link('&laquo; %link') ?></div>
			<div class="alignright"><?php next_post_link('%link &raquo;') ?></div>
			<div style="clear:both;"></div>
		</div>
		<div class="post" id="post-<?php the_ID(); ?>">
			<h2><a href="&lt;?php echo get_permalink() ?&gt;" rel="bookmark" title="Permanent Link: <?php the_title(); ?>"><?php the_title(); ?></a></h2>
		<!-- display the postmetadata -->
		<div class="postmetadata">
      	<?php the_time('Y/m/d') ?>&nbsp;&nbsp;&nbsp;<?php the_tags('Tags: ', ', ', ''); ?>
		</div>
			<div class="entrytext">
				<?php the_content('<p class="serif">阅读全文 &raquo;</p>'); ?>
				<?php if(function_exists('the_ratings')) { echo '<div class="postmetadata p_ratings">评价本文:'; the_ratings(); echo '</div>'; } ?>
				<?php link_pages('<p><strong>页:</strong> ', '</p>', 'number'); ?>
				<div style="clear:both;"></div>
			</div>
		</div>
	<?php include('adsense_singlepost_bottom_square.php') ?>
	<?php comments_template(); ?>
	<?php endwhile; else: ?>
		<p>不好意思,没有找到符合您条件的文章。</p>
<?php endif; ?>
	</div>
<?php get_sidebar(); ?>
</div>
<?php get_footer(); ?>
二、tab转换成空格后
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php get_header(); ?>
<div id="wrapper">
   <div id="content">
   <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
      <div class="navigation">
         <div class="alignleft"><?php previous_post_link('&laquo; %link') ?></div>
         <div class="alignright"><?php next_post_link('%link &raquo;') ?></div>
         <div style="clear:both;"></div>
      </div>
      <div class="post" id="post-<?php the_ID(); ?>">
         <h2><a href="&lt;?php echo get_permalink() ?&gt;" rel="bookmark" title="Permanent Link: <?php the_title(); ?>"><?php the_title(); ?></a></h2>
      <!-- display the postmetadata -->
      <div class="postmetadata">
         <?php the_time('Y/m/d') ?>&nbsp;&nbsp;&nbsp;<?php the_tags('Tags: ', ', ', ''); ?>
      </div>
         <div class="entrytext">
            <?php the_content('<p class="serif">阅读全文 &raquo;</p>'); ?>
            <?php if(function_exists('the_ratings')) { echo '<div class="postmetadata p_ratings">评价本文:'; the_ratings(); echo '</div>'; } ?>
            <?php link_pages('<p><strong>页:</strong> ', '</p>', 'number'); ?>
            <div style="clear:both;"></div>
         </div>
      </div>
   <?php include('adsense_singlepost_bottom_square.php') ?>
   <?php comments_template(); ?>
   <?php endwhile; else: ?>
      <p>不好意思,没有找到符合您条件的文章。</p>
<?php endif; ?>
   </div>
<?php get_sidebar(); ?>
</div>
<?php get_footer(); ?>

很多文本编辑器都有tab转换空格的功能,alfie用的是UltraEdit-32。