
from pelican import signals
import re


def embed_tweet(content):
    content._content = re.sub(
        r'(^|[^@\w])@(\w{1,15})\b',
        '\\1<a href="https://twitter.com/\\2">@\\2</a>',
        re.sub(
            r'(^|[^@\w])@(\w{1,15})/status/(\d+)\b',
            '\\1<blockquote class="twitter-tweet" align="center"><a href="https://twitter.com/\\2/status/\\3">Tweet of \\2/\\3</a></blockquote>',
            content._content
        )
    ) + '<script src="//platform.twitter.com/widgets.js" charset="utf-8"></script>'


def register():
    signals.content_object_init.connect(embed_tweet)


from pelican import signals
import re


def embed_tweet(content):
    if not content._content:
        return

    content._content = re.sub(
        r'(^|[^@\w])@(\w{1,15})\b',
        '\\1<a href="https://twitter.com/\\2">@\\2</a>',
        re.sub(
            r'(^|[^@\w])@(\w{1,15})/status/(\d+)\b',
            '\\1<blockquote class="twitter-tweet" align="center"><a href="https://twitter.com/\\2/status/\\3">Tweet of \\2/\\3</a></blockquote>',
            content._content
        )
    ) + '<script src="//platform.twitter.com/widgets.js" charset="utf-8"></script>'


def register():
    signals.content_object_init.connect(embed_tweet)

Check content._content before using it to prevent errors
Check content._content before using it to prevent errors

  
  from pelican import signals
  import re
  
  
  def embed_tweet(content):
+     if not content._content:
+         return
+ 
      content._content = re.sub(
          r'(^|[^@\w])@(\w{1,15})\b',
          '\\1<a href="https://twitter.com/\\2">@\\2</a>',
          re.sub(
              r'(^|[^@\w])@(\w{1,15})/status/(\d+)\b',
              '\\1<blockquote class="twitter-tweet" align="center"><a href="https://twitter.com/\\2/status/\\3">Tweet of \\2/\\3</a></blockquote>',
              content._content
          )
      ) + '<script src="//platform.twitter.com/widgets.js" charset="utf-8"></script>'
  
  
  def register():
      signals.content_object_init.connect(embed_tweet)
  
Check content._content before using it to prevent errors
## Code Before:

from pelican import signals
import re


def embed_tweet(content):
    content._content = re.sub(
        r'(^|[^@\w])@(\w{1,15})\b',
        '\\1<a href="https://twitter.com/\\2">@\\2</a>',
        re.sub(
            r'(^|[^@\w])@(\w{1,15})/status/(\d+)\b',
            '\\1<blockquote class="twitter-tweet" align="center"><a href="https://twitter.com/\\2/status/\\3">Tweet of \\2/\\3</a></blockquote>',
            content._content
        )
    ) + '<script src="//platform.twitter.com/widgets.js" charset="utf-8"></script>'


def register():
    signals.content_object_init.connect(embed_tweet)

## Instruction:
Check content._content before using it to prevent errors
## Code After:

from pelican import signals
import re


def embed_tweet(content):
    if not content._content:
        return

    content._content = re.sub(
        r'(^|[^@\w])@(\w{1,15})\b',
        '\\1<a href="https://twitter.com/\\2">@\\2</a>',
        re.sub(
            r'(^|[^@\w])@(\w{1,15})/status/(\d+)\b',
            '\\1<blockquote class="twitter-tweet" align="center"><a href="https://twitter.com/\\2/status/\\3">Tweet of \\2/\\3</a></blockquote>',
            content._content
        )
    ) + '<script src="//platform.twitter.com/widgets.js" charset="utf-8"></script>'


def register():
    signals.content_object_init.connect(embed_tweet)
