灏天阁

Node/Koa2[68]:@用户转为链接形式

· Yin灏

格式化@内容

// src/services/_format.js
function _formatContent(obj) {
  obj.contentFormat = obj.content;
  obj.contentFormat = obj.contentFormat.replace(
    /@(.+?)\s-\s(\w+?)\b/g,
    (matchStr, nickName, userName) => {
      return `<a href="/profile/${userName}">@${nickName}</a>`;
    }
  );
}

- Book Lists -