def build_note_content(note_body, resources):
    """Return notebook content with attachments written in Evernote Markup Language.

    Parameters
    ----------
    note_body : str
        Custom content to insert before attachments

    resources : list of evernote.edam.type.ttypes.Resource
        List of attachments to combined with the note

    Returns
    -------
    note_content : str

    Notes
    -----
    Understanding the Evernote Markup Language:
        https://dev.evernote.com/doc/articles/enml.php


    """
    note_content = '<?xml version="1.0" encoding="UTF-8"?>'
    note_content += '<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">'
    note_content += "<en-note>%s" % note_body

    if resources:
        # add Resource objects to note content
        note_content += "<br />" * 2

        for resource in resources:
            hexhash = resource.data.bodyHash
            note_content += "<br /><en-media type=\"%s\" hash=\"%s\" /><br />" % (resource.mime, hexhash)
    note_content += "</en-note>"

    # handling encoding
    for title_charset in 'US-ASCII', 'ISO-8859-1', 'UTF-8':
        try:
            note_content = note_content.encode(title_charset)
        except UnicodeError:
            pass
        else:
            break

    return note_content