0

我将 Github Pages 用于我的个人网站。他们正在从 Jekyll 2 升级到 Jekyll 3 并发送弃用警告。我遵守了他们的警告,从 redcarpet 切换到 kramdown,从 pygments 切换到 rouge。当我在本地(使用)构建时,bundle exec jekyll serve一切正常。但是当我推送更改时,语法突出显示linenos在我的代码块中的任何地方都会被破坏。

这是代码块:

{% highlight python linenos %}
'''
scrape lyrics from vagalume.com.br
(author: thiagomarzagao.com)
'''

import json
import time
import pickle
import requests
from bs4 import BeautifulSoup

# get each genre's URL
basepath = 'http://www.vagalume.com.br'
r = requests.get(basepath + '/browse/style/')
soup = BeautifulSoup(r.text)
genres = [u'Rock']
          u'Ax\u00E9',
          u'Forr\u00F3',
          u'Pagode',
          u'Samba',
          u'Sertanejo',
          u'MPB',
          u'Rap']
genre_urls = {}
for genre in genres:
    genre_urls[genre] = soup.find('a', class_ = 'eA', text = genre).get('href')

# get each artist's URL, per genre
artist_urls = {e: [] for e in genres}
for genre in genres:
    r = requests.get(basepath + genre_urls[genre])
    soup = BeautifulSoup(r.text)
    counter = 0
    for artist in soup.find_all('a', class_ = 'top'):
        counter += 1
        print 'artist {} \r'.format(counter)
        artist_urls[genre].append(basepath + artist.get('href'))
    time.sleep(2) # don't reduce the 2-second wait (here or below) or you get errors

# get each lyrics, per genre
api = 'http://api.vagalume.com.br/search.php?musid='
genre_lyrics = {e: {} for e in genres}
for genre in artist_urls:
    print len(artist_urls[genre])
    counter = 0
    artist1 = None
    for url in artist_urls[genre]:
        success = False
        while not success: # foor loop in case your connection flickers
            try:
                r = requests.get(url)
                success = True
            except:
                time.sleep(2)
        soup = BeautifulSoup(r.text)
        hrefs = soup.find_all('a')
        for href in hrefs:
            if href.has_attr('data-song'):
                song_id = href['data-song']
                print song_id
                time.sleep(2)
                success = False
                while not success:
                    try:
                        song_metadata = requests.get(api + song_id).json()
                        success = True
                    except:
                        time.sleep(2)
                if 'mus' in song_metadata:
                    if 'lang' in song_metadata['mus'][0]: # discard if no language info
                        language = song_metadata['mus'][0]['lang']
                        if language == 1: # discard if language != Portuguese
                            if 'text' in song_metadata['mus'][0]: # discard if no lyrics
                                artist2 = song_metadata['art']['name']
                                if artist2 != artist1:
                                    if counter > 0:
                                        print artist1.encode('utf-8') # change as needed
                                        genre_lyrics[genre][artist1] = artist_lyrics
                                    artist1 = artist2
                                    artist_lyrics = []
                                lyrics = song_metadata['mus'][0]['text']
                                artist_lyrics.append(lyrics)
                                counter += 1
                                print 'lyrics {} \r'.format(counter)

    # serialize
    with open(genre + '.json', mode = 'wb') as fbuffer:
        json.dump(genre_lyrics[genre], fbuffer)
{% endhighlight %}

这是我在本地看到的:

在此处输入图像描述

这是我在 Github 页面上看到的:

在此处输入图像描述

(没有linenos语法高亮效果很好。)

会发生什么?

4

1 回答 1

1

我想我明白了!

您的代码块似乎很好。那里没问题。

确保您已将其添加到您的_config.yml

highlighter: rouge
markdown: kramdown
kramdown:
  input: GFM

可能你缺少的是kramdown input: GFM,不是吗?

好吧,我在本地测试并且工作正常。上传到 GitHub时,效果也很好。也应该为你工作。

让我知道进展如何,好吗?:)


更新!

将此添加到您的样式表并检查它是如何进行的:

.lineno { width: 35px; }

看起来是您的 CSS 样式破坏了布局!继续调整你的 CSS,你会没事的!

于 2016-02-11T22:45:14.457 回答