I'm working with an interesting API that returns each element of a resource in it's own object. I'm passing the data from an ng-repeat into a directive which I need to then return the completed HTML string. Brand new to lodash and having a bit of trouble figuring this one out. There are quite a few possibilities of segment types that I'll need to end up having cases for. View API Docs
- Link
- Mention
- Hashtag
- MarkupBegin
- MarkupEnd
- etc
NG Directive
angular.module('Community.directives.feedBody', [])
.directive('feedBody', function feedBodyDirective() {
return {
restrict: 'E',
link: convertSegments
};
function convertSegments($scope, elem, attrs) {
var content = attrs.content;
}
}
);
JSON
[
{
"htmlTag": "p",
"markupType": "Paragraph",
"text": "",
"type": "MarkupBegin"
},
{
"text": "This is a ",
"type": "Text"
},
{
"htmlTag": "b",
"markupType": "Bold",
"text": "",
"type": "MarkupBegin"
},
{
"text": "post",
"type": "Text"
},
{
"htmlTag": "b",
"markupType": "Bold",
"text": "",
"type": "MarkupEnd"
},
{
"text": " from the standard ",
"type": "Text"
},
{
"htmlTag": "i",
"markupType": "Italic",
"text": "",
"type": "MarkupBegin"
},
{
"text": "chatter",
"type": "Text"
},
{
"htmlTag": "i",
"markupType": "Italic",
"text": "",
"type": "MarkupEnd"
},
{
"text": " UI with some HTML tags",
"type": "Text"
},
{
"htmlTag": "p",
"markupType": "Paragraph",
"text": "\n",
"type": "MarkupEnd"
}
]
UI Router Template
<feed-body content="{{comment.body.messageSegments}}"></feed-body>
Should Return
<p><b>post</b> from the standard <i>chatter</i> ui with some HTML tags</p>