コード例 #1
0
func TestRenderMarkdownContentWithFence(t *testing.T) {
	content := "``` go\nfunc getTrue() bool {return true}\n```"
	result := rendering.RenderMarkupToHTML(content, rendering.SystemMarkupMarkdown)
	t.Log(result)
	require.NotNil(t, result)
	assert.True(t, strings.Contains(result, "<code class=\"language-go\">"))
}
コード例 #2
0
func TestRenderMarkdownContent(t *testing.T) {
	content := "Hello, `World`!"
	result := rendering.RenderMarkupToHTML(content, rendering.SystemMarkupMarkdown)
	t.Log(result)
	require.NotNil(t, result)
	assert.Equal(t, "<p>Hello, <code>World</code>!</p>\n", result)
}
コード例 #3
0
ファイル: comments.go プロジェクト: Ritsyy/almighty-core
// ConvertComment converts between internal and external REST representation
func ConvertComment(request *goa.RequestData, comment *comment.Comment, additional ...CommentConvertFunc) *app.Comment {
	selfURL := rest.AbsoluteURL(request, app.CommentsHref(comment.ID))
	markup := rendering.NilSafeGetMarkup(&comment.Markup)
	bodyRendered := rendering.RenderMarkupToHTML(html.EscapeString(comment.Body), comment.Markup)
	c := &app.Comment{
		Type: "comments",
		ID:   &comment.ID,
		Attributes: &app.CommentAttributes{
			Body:         &comment.Body,
			BodyRendered: &bodyRendered,
			Markup:       &markup,
			CreatedAt:    &comment.CreatedAt,
		},
		Relationships: &app.CommentRelations{
			CreatedBy: &app.CommentCreatedBy{
				Data: &app.IdentityRelationData{
					Type: "identities",
					ID:   &comment.CreatedBy,
				},
			},
		},
		Links: &app.GenericLinks{
			Self: &selfURL,
		},
	}
	for _, add := range additional {
		add(request, comment, c)
	}
	return c
}
コード例 #4
0
ファイル: render.go プロジェクト: Ritsyy/almighty-core
// Render runs the render action.
func (c *RenderController) Render(ctx *app.RenderRenderContext) error {
	content := ctx.Payload.Data.Attributes.Content
	markup := ctx.Payload.Data.Attributes.Markup
	if !rendering.IsMarkupSupported(markup) {
		return jsonapi.JSONErrorResponse(ctx, errors.NewBadParameterError("Unsupported markup type", markup))
	}
	htmlResult := rendering.RenderMarkupToHTML(content, markup)
	res := &app.MarkupRenderingSingle{Data: &app.MarkupRenderingData{
		ID:   uuid.NewV4().String(),
		Type: RenderingType,
		Attributes: &app.MarkupRenderingDataAttributes{
			RenderedContent: htmlResult,
		}}}
	return ctx.OK(res)
}
コード例 #5
0
func (rest *TestCommentREST) assertComment(c *app.Comment, expectedBody string, expectedMarkup string) {
	assert.NotNil(rest.T(), c)
	assert.Equal(rest.T(), "comments", c.Type)
	assert.NotNil(rest.T(), c.ID)
	require.NotNil(rest.T(), c.Attributes)
	assert.Equal(rest.T(), expectedBody, *c.Attributes.Body)
	assert.Equal(rest.T(), expectedMarkup, *c.Attributes.Markup)
	assert.Equal(rest.T(), rendering.RenderMarkupToHTML(html.EscapeString(expectedBody), expectedMarkup), *c.Attributes.BodyRendered)
	require.NotNil(rest.T(), c.Attributes.CreatedAt)
	assert.WithinDuration(rest.T(), time.Now(), *c.Attributes.CreatedAt, 2*time.Second)
	require.NotNil(rest.T(), c.Relationships)
	require.NotNil(rest.T(), c.Relationships.CreatedBy)
	require.NotNil(rest.T(), c.Relationships.CreatedBy.Data)
	assert.Equal(rest.T(), "identities", c.Relationships.CreatedBy.Data.Type)
	assert.NotNil(rest.T(), c.Relationships.CreatedBy.Data.ID)
}
コード例 #6
0
func (s *CommentsSuite) validateComment(result *app.CommentSingle, expectedBody string, expectedMarkup string) {
	require.NotNil(s.T(), result)
	require.NotNil(s.T(), result.Data)
	assert.NotNil(s.T(), result.Data.ID)
	assert.NotNil(s.T(), result.Data.Type)
	require.NotNil(s.T(), result.Data.Attributes)
	require.NotNil(s.T(), result.Data.Attributes.Body)
	assert.Equal(s.T(), expectedBody, *result.Data.Attributes.Body)
	require.NotNil(s.T(), result.Data.Attributes.Markup)
	assert.Equal(s.T(), expectedMarkup, *result.Data.Attributes.Markup)
	assert.Equal(s.T(), rendering.RenderMarkupToHTML(html.EscapeString(expectedBody), expectedMarkup), *result.Data.Attributes.BodyRendered)
	require.NotNil(s.T(), result.Data.Relationships)
	require.NotNil(s.T(), result.Data.Relationships.CreatedBy)
	require.NotNil(s.T(), result.Data.Relationships.CreatedBy.Data)
	require.NotNil(s.T(), result.Data.Relationships.CreatedBy.Data.ID)
	assert.Equal(s.T(), testsupport.TestIdentity.ID, *result.Data.Relationships.CreatedBy.Data.ID)
}
コード例 #7
0
ファイル: workitem.go プロジェクト: Ritsyy/almighty-core
// ConvertWorkItem is responsible for converting given WorkItem model object into a
// response resource object by jsonapi.org specifications
func ConvertWorkItem(request *goa.RequestData, wi *app.WorkItem, additional ...WorkItemConvertFunc) *app.WorkItem2 {
	// construct default values from input WI
	selfURL := rest.AbsoluteURL(request, app.WorkitemHref(wi.ID))
	sourceLinkTypesURL := rest.AbsoluteURL(request, app.WorkitemtypeHref(wi.Type)+sourceLinkTypesRouteEnd)
	targetLinkTypesURL := rest.AbsoluteURL(request, app.WorkitemtypeHref(wi.Type)+targetLinkTypesRouteEnd)
	op := &app.WorkItem2{
		ID:   &wi.ID,
		Type: APIStringTypeWorkItem,
		Attributes: map[string]interface{}{
			"version": wi.Version,
		},
		Relationships: &app.WorkItemRelationships{
			BaseType: &app.RelationBaseType{
				Data: &app.BaseTypeData{
					ID:   wi.Type,
					Type: APIStringTypeWorkItemType,
				},
			},
		},
		Links: &app.GenericLinksForWorkItem{
			Self:            &selfURL,
			SourceLinkTypes: &sourceLinkTypesURL,
			TargetLinkTypes: &targetLinkTypesURL,
		},
	}

	// Move fields into Relationships or Attributes as needed
	// TODO: Loop based on WorKItemType and match against Field.Type instead of directly to field value
	for name, val := range wi.Fields {
		switch name {
		case workitem.SystemAssignees:
			if val != nil {
				valArr := val.([]interface{})
				op.Relationships.Assignees = &app.RelationGenericList{
					Data: ConvertUsersSimple(request, valArr),
				}
			}
		case workitem.SystemCreator:
			if val != nil {
				valStr := val.(string)
				op.Relationships.Creator = &app.RelationGeneric{
					Data: ConvertUserSimple(request, valStr),
				}
			}
		case workitem.SystemIteration:
			if val != nil {
				valStr := val.(string)
				op.Relationships.Iteration = &app.RelationGeneric{
					Data: ConvertIterationSimple(request, valStr),
				}
			}
		case workitem.SystemArea:
			if val != nil {
				valStr := val.(string)
				op.Relationships.Area = &app.RelationGeneric{
					Data: ConvertAreaSimple(request, valStr),
				}
			}

		case workitem.SystemTitle:
			// 'HTML escape' the title to prevent script injection
			op.Attributes[name] = html.EscapeString(val.(string))
		case workitem.SystemDescription:
			description := rendering.NewMarkupContentFromValue(val)
			if description != nil {
				op.Attributes[name] = (*description).Content
				op.Attributes[workitem.SystemDescriptionMarkup] = (*description).Markup
				// let's include the rendered description while 'HTML escaping' it to prevent script injection
				op.Attributes[workitem.SystemDescriptionRendered] =
					rendering.RenderMarkupToHTML(html.EscapeString((*description).Content), (*description).Markup)
			}

		default:
			op.Attributes[name] = val
		}
	}
	if op.Relationships.Assignees == nil {
		op.Relationships.Assignees = &app.RelationGenericList{Data: nil}
	}
	if op.Relationships.Iteration == nil {
		op.Relationships.Iteration = &app.RelationGeneric{Data: nil}
	}
	if op.Relationships.Area == nil {
		op.Relationships.Area = &app.RelationGeneric{Data: nil}
	}
	// Always include Comments Link, but optionally use WorkItemIncludeCommentsAndTotal
	WorkItemIncludeComments(request, wi, op)
	for _, add := range additional {
		add(request, wi, op)
	}
	return op
}